Hi everyone, this code is failing on test cases [1, 13] and [23, 18]. I’ve tested it on two other Node editors and it works. Would appreciate some help.
function smallestCommons(arr) {
arr = arr.sort((a, b) => a - b);
const range = [];
for(let i = arr[0]; i <= arr[1]; i++) {
range.push(i);
}
const product = range.reduce((acc, curr) => acc * curr);
for(let i = range[range.length - 1] + 1; i <= product; i++) {
if(range.every(num => i % num == 0)) {
return i;
}
}
}