Skip to content

Instantly share code, notes, and snippets.

@TerryZ
Created August 22, 2018 13:50
Show Gist options
  • Save TerryZ/05fec2a75912e55dcad71a723420f843 to your computer and use it in GitHub Desktop.
Save TerryZ/05fec2a75912e55dcad71a723420f843 to your computer and use it in GitHub Desktop.
最小公约数计算
function gcd(a,b){
var minNum = Math.min(a,b),maxNum = Math.max(a,b),i=minNum,vper=0;
if(a ===0 || b===0) return maxNum;
for(var i=1;i<=maxNum;i++){
vper = minNum * i;
if(vper % maxNum === 0){
return vper;
break;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment