From 7e97146e97c0b3d11aab98a452a21abee98f5d0a Mon Sep 17 00:00:00 2001 From: Colin Xie Date: Sun, 4 Jun 2017 18:36:19 -0700 Subject: [PATCH 1/3] solve issue #61 find GCD --- solutions/61.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 solutions/61.js diff --git a/solutions/61.js b/solutions/61.js new file mode 100644 index 0000000..03cf107 --- /dev/null +++ b/solutions/61.js @@ -0,0 +1,23 @@ +// Takes in two numbers and returns their greatest common denominator (GCD) + +// Input: 16,24 +// Output: 8 + +// Solutions by Colin Xie @ColinX13 + +/** + * Factor is determined when both remainders of num1 and num2 are 0 when factor is divided from them. + * @param num1 - the first number input + * @param num2 - the second number input + * @return {number} factor - the greatest common factor for num1 and num2 +*/ +const solution = (num1, num2) => { + for(factor = num1; factor >= 1; factor--){ + if(num1 % factor === 0 && num2 % factor === 0){ + return factor; + } + } +}; +module.exports = { + solution +}; From b96ac579789004e1a529e259700d30d0a3b4181a Mon Sep 17 00:00:00 2001 From: Colin Xie Date: Sun, 4 Jun 2017 18:46:04 -0700 Subject: [PATCH 2/3] test #61 --- test/61.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 test/61.js diff --git a/test/61.js b/test/61.js new file mode 100644 index 0000000..49d6f3b --- /dev/null +++ b/test/61.js @@ -0,0 +1,24 @@ +const expect = require('chai').expect; +let solution = require('../solutions/61').solution; +// solution = require('./yourSolution').solution; + +describe('greatest common denominator', () => { + it('the gcd for 16 and 24 is 8', () => { + expect(solution(16,24)).eql(8); + }); + it('the gcd for 5 and 6 is 1', () => { + expect(solution(5,6)).eql(1); + }); + it('the gcd for 50 and 60 is 10', () => { + expect(solution(50,60)).eql(10); + }); + it('the gcd for 40 and 20 is 20', () => { + expect(solution(40,20)).eql(20); + }); + it('the gcd for 20 and 40 is 20', () => { + expect(solution(20,40)).eql(20); + }); + it('the gcd for 1 and 4 is 1', () => { + expect(solution(1,4)).eql(1); + }); +}); From 377c1c59ebf25e744541af42bcc3526d2e379149 Mon Sep 17 00:00:00 2001 From: Colin Xie Date: Sun, 4 Jun 2017 19:23:31 -0700 Subject: [PATCH 3/3] Updated #61 --- solutions/61.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/solutions/61.js b/solutions/61.js index 03cf107..a65a660 100644 --- a/solutions/61.js +++ b/solutions/61.js @@ -12,7 +12,7 @@ * @return {number} factor - the greatest common factor for num1 and num2 */ const solution = (num1, num2) => { - for(factor = num1; factor >= 1; factor--){ + for(let factor = num1; factor >= 1; factor--){ if(num1 % factor === 0 && num2 % factor === 0){ return factor; }