Created
April 15, 2017 02:07
-
-
Save voronoipotato/75507c74c025661552318acb6d531f66 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
/* | |
let rec gcd a b = | |
match a, b with | |
| _ , 0 -> a | |
| _ , _ -> gcd b (a%b) | |
let lcm a b = a * b / (gcd a b) | |
*/ | |
var arr = [1,2,3,4,5] | |
var lcmList = function(a) { | |
var gcd = function(a,b){ | |
if(b==0){ | |
return a; | |
}else{ | |
return gcd(b,a%b) | |
} | |
} | |
var lcm = function(a,b){ | |
return a*b/gcd(a,b) | |
} | |
return a.reduce(lcm) | |
} | |
lcmList(arr) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment