Skip to content

Commit

Permalink
solve issue llipio#61 find GCD
Browse files Browse the repository at this point in the history
  • Loading branch information
ColinX13 committed Jun 5, 2017
1 parent cc60d0d commit 7e97146
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions solutions/61.js
Original file line number Diff line number Diff line change
@@ -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
};

0 comments on commit 7e97146

Please sign in to comment.