Skip to content

Instantly share code, notes, and snippets.

@codebubb
Created December 7, 2015 22:05
Show Gist options
  • Select an option

  • Save codebubb/cd230970985c641be184 to your computer and use it in GitHub Desktop.

Select an option

Save codebubb/cd230970985c641be184 to your computer and use it in GitHub Desktop.
// Bonfire: Smallest Common Multiple
// Author: @codebubb
// Challenge: http://www.freecodecamp.com/challenges/bonfire-smallest-common-multiple#
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function smallestCommons(arr) {
var nums = range(arr[0], arr[1]);
return nums.reduce(lcm);
}
function gcd(a,b){
return b === 0 ? a : gcd(b, a % b);
}
function lcm(a,b){
return a * b / gcd(a,b);
}
function range(a,b){
var arr = [];
if(a > b) b = [a, a = b][0];
for(; a<=b; a++) arr.push(a);
return arr;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment