Skip to content

Commit

Permalink
llipio#60 test and solutions
Browse files Browse the repository at this point in the history
  • Loading branch information
ColinX13 committed Jun 3, 2017
1 parent 1d946df commit 8bdb67a
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
23 changes: 23 additions & 0 deletions solutions/60.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//Return the sum of all factors in x
//Intialize sum to equal 0
//Factor i of number have mod equal to 0
//Reassign sum to equal to sum plus i
//Run through for loop
//input [2,4,10,24]
//output [3,7,18,60]

// Solution by Colin Xie @ColinX13

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 8bdb67a

Please sign in to comment.