Skip to content

Instantly share code, notes, and snippets.

@musantro
Created November 18, 2015 16:12
Show Gist options
  • Save musantro/b14ffd12515d5f1fc105 to your computer and use it in GitHub Desktop.
Save musantro/b14ffd12515d5f1fc105 to your computer and use it in GitHub Desktop.
Small js file to find the smallest Commons between 2 numbers
function smallestCommons(arr) {
arr.sort();
var first = arr[0];
var last = arr[1];
var multiplier = 1;
var bool = [];
var multiple = 0;
while(bool.length < last){
bool = [];
multiple = multiplier*last;
for(j=first; j<=last;j++){
if((multiple%j)===0){
bool.push(true);
}
else {
break;
}
}
console.log("multiple= ",multiple,"bool.length = ",bool.length);
multiplier++;
}
return multiple;
}
smallestCommons([1,13]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment