Last active
April 24, 2016 11:50
-
-
Save black-black-cat/a44bb311c111ee47eade to your computer and use it in GitHub Desktop.
计算多个数字的最小公倍数
This file contains 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 minComMulti() { | |
var args = [].slice.call(arguments); | |
var len = args.length; | |
if (len < 1) return; | |
if (len === 1) return args[0]; | |
if (len === 2) { | |
// minTwoMulti(); | |
var max = Math.max.apply(Math, args); | |
var min = Math.min.apply(Math, args); | |
for (var i = 1;; i++) { | |
if (max * i % min === 0) { | |
return max * i; | |
} | |
} | |
} | |
return minComMulti(minComMulti.apply( null, args.slice(1) ), args[0]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment