hello all
I got confused, why doesn’t it pass the (18, 23) test…?
let smallestCommons = (arr) => {
let min = Math.min(...arr), max = Math.max(...arr);
let smallestC = (min, min + 1);
while (min < max) {
min++;
smallestC = lcm(smallestC, min);
}
return smallestC;
}
let lcm = (a,b) => {
return (a * b / gcd_nums(a, b))
}
let gcd_nums = (x, y) => {
while (y) {
let temp = y;
y = x % y;
x = temp;
}
return x;
}
console.log(smallestCommons([18,23]));
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:66.0) Gecko/20100101 Firefox/66.0
.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/smallest-common-multiple