Skip to content

Commit

Permalink
Merge pull request #6 from bunnydeviloper/problem7
Browse files Browse the repository at this point in the history
solved #7: input number and return largest divisor
  • Loading branch information
bunnydeviloper authored Oct 20, 2017
2 parents a9c253a + e0a03f7 commit 0d1ea59
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
11 changes: 11 additions & 0 deletions solutions/7.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const getDivisors = (number, i=1) => {
if ((number%(number - i)) === 0) {
return (number - i);
}
return getDivisors(number, i+1);
};

module.exports = getDivisors;



15 changes: 15 additions & 0 deletions test/7.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const getDivisors = require('../solutions/7.js');

const test = (testNumber, trueResult) => {
if (getDivisors(testNumber) === trueResult) {
console.log(`Largest divisor of ${testNumber} is ${trueResult}`);
} else {
console.log('Check your code again');
}
};

test(10,5);
test(20,20);
test(35,7);
test(55,10);

0 comments on commit 0d1ea59

Please sign in to comment.