Skip to content

Instantly share code, notes, and snippets.

@scq000
Last active September 2, 2017 02:17
Show Gist options
  • Save scq000/223b1e7e3ab692516a7df96774d5db12 to your computer and use it in GitHub Desktop.
Save scq000/223b1e7e3ab692516a7df96774d5db12 to your computer and use it in GitHub Desktop.
最小公倍数和最大公约数
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