I’ve done Intermediate Algorithm Scripting: Smallest Common Multiple.
I’ve tested my code and it works on all test cases but when I paste it to fcc code editor it tells me that for smallestCommons([1, 13]) and smallestCommons([23, 18]) my code is not working.
Is my code wrong or is it issue with fcc?
function smallestCommons(arr) {
let finalNum = 0;
const range = [];
arr.sort((a, b) => a - b);
for (let i = arr[0]; i <= arr[1]; i += 1) {
range.push(i);
}
function check(num) {
if (range.every(el => num % el === 0)) {
finalNum = num;
return true;
}
}
let count = 2;
let number = 1;
while (!check(number)) {
number = arr[0] * count;
count += 1;
}
return finalNum;
}
console.log(smallestCommons([1, 13])); // 360360
console.log(smallestCommons([23, 18])); // 6056820