Tell us what’s happening:
I really don’t like that static number inside my for-loop and have no idea of a work around with a while loop. Can anybody show me a simple way how to get rid of the static value?
**Your code so far**
function smallestCommons(arr) {
let sm = Math.min(...arr);
let bg = Math.max(...arr);
var arrCheck = []
for (let i = sm; i<bg+1;i++){
arrCheck.push(i)
}
for (let j = 2; j < 100000000;j++){
var arr2 = arrCheck.map(x => j % x)
if (arr2.every(elem => elem == 0)){
console.log(j)
return j
}
}
}
smallestCommons([1,5]);
**Your browser information:**
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.183 Safari/537.36
.
Challenge: Smallest Common Multiple
Link to the challenge: