Last active
September 2, 2017 02:17
-
-
Save scq000/223b1e7e3ab692516a7df96774d5db12 to your computer and use it in GitHub Desktop.
最小公倍数和最大公约数
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function gcd(a,b){ | |
return a%b === 0 ? b: gcd(b, a % b); | |
} | |
function lcm(a,b) { | |
return a * b / gcd(a, b); | |
} | |
function lcms(...nums) { | |
let result = 1; | |
for(let i = 0; i < nums.length; i++) { | |
result = lcm(result, nums[i]); | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment