Skip to content

Commit

Permalink
Merge pull request #65 from ColinX13/colin3
Browse files Browse the repository at this point in the history
#60 test and solutions
  • Loading branch information
yjlim5 authored Jun 5, 2017
2 parents 69e047a + 359d36d commit fde5bb0
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
25 changes: 25 additions & 0 deletions solutions/60.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Sum of its factors
// Given a number, return the sum of all of its factors.
// input: 2
// output: 3

// Solution by Colin Xie @ColinX13

/*
* @param {number} x - A number input
* @returns {number} sum - The sum of all the factors of the number
*/
const solution = (x) => {
let sum = 0;
for(let i = x; i >= 1; i--){
if(x % i === 0){
sum = sum + i;
}
}
return sum;
};

module.exports = {
solution
};

19 changes: 19 additions & 0 deletions test/60.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const expect = require('chai').expect;
let solution = require('../solutions/60').solution;
// solution = require('./yourSolution').solution;

describe('sum of factors', () => {
it('sum of the factors of 2 is 3', () => {
expect(solution(2)).eql(3);
});
it('sum of the factors of 4 is 7', () => {
expect(solution(4)).eql(7);
});
it('sum of the factors of 10 is 18', () => {
expect(solution(10)).eql(18);
});
it('sum of the factors of 24', () => {
expect(solution(24)).eql(60);
});
});

0 comments on commit fde5bb0

Please sign in to comment.