Created
November 18, 2015 16:12
-
-
Save musantro/b14ffd12515d5f1fc105 to your computer and use it in GitHub Desktop.
Small js file to find the smallest Commons between 2 numbers
This file contains hidden or 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 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