Skip to content

Instantly share code, notes, and snippets.

@voronoipotato
Created April 15, 2017 02:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save voronoipotato/75507c74c025661552318acb6d531f66 to your computer and use it in GitHub Desktop.
Save voronoipotato/75507c74c025661552318acb6d531f66 to your computer and use it in GitHub Desktop.
/*
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