Hello guys,
what do you think about this cheesy solution to the problem in algorithms, to find the smallest common multiple? It really struggles with numbers that are greater than 20.
function smallestCommons(arr) {
const myArr = arr.sort((x, y) => x - y);
const rangeOfNums = [];
for (let i = myArr[0]; i <= myArr[1]; i++) { rangeOfNums.push(i) };
for (let i = 1; true; i++) {
if (rangeOfNums.every(x => i % x == 0)) {
return i;
}
}
}
console.log(smallestCommons([1, 20]));