Skip to content

Commit

Permalink
solution and test for llipio#21
Browse files Browse the repository at this point in the history
  • Loading branch information
bettychow committed May 8, 2017
1 parent bd27ba1 commit ed6f7a7
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
25 changes: 25 additions & 0 deletions solutions/21.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

const largestDesNums = (array) => {
let newArray = [];
array.sort(function(a,b) { return b - a });

for (let i = 0; i<3; i++) {
newArray.push(array[i]);
}

return (
newArray
);
};

module.exports = {
largestDesNums
};








22 changes: 22 additions & 0 deletions test/21.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

const expect = require('chai').expect;
let largestDesNums = require('../solutions/21').largestDesNums

describe('Largest Three Numbers', () => {
it('should return the 3 largest numbers in descending order', () => {
const result = largestDesNums([1,9,8,7]);
expect(result).to.deep.equal([9,8,7]);
});

it('should return the 3 largest numbers in descending order', () => {
const result = largestDesNums([11,34,29,76]);
expect(result).to.deep.equal([76,34,29]);
});

it('should return the 3 largest numbers in descending order', () => {
const result = largestDesNums([234,123,456,345,897]);
expect(result).to.deep.equal([897,456,345]);
});
});


0 comments on commit ed6f7a7

Please sign in to comment.