Created
March 28, 2018 01:43
-
-
Save ronaldoarg/094edf64da0e9e905e035dccaa1960af to your computer and use it in GitHub Desktop.
My solution for FreeCodeCamp Smallest Common Multiple Challenge
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
// https://www.freecodecamp.org/challenges/smallest-common-multiple | |
function smallestCommons(arr) { | |
var max = Math.max.apply(this, arr), | |
min = Math.min.apply(this, arr), | |
multiple = max, | |
numbers = []; | |
for(var count = min; count <= max; count++) { | |
numbers.push(count); | |
} | |
while(!isSCM(multiple, numbers)) { | |
multiple += max; | |
} | |
return multiple; | |
} | |
function isSCM(multiple, numbers) { | |
return !numbers.map(function(item) { | |
return (multiple % item == 0); | |
}).some(function(item) { | |
return item == false; | |
}); | |
} | |
smallestCommons([23, 18]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment