Tell us what’s happening:
SO, everything is working fine, except for the last test, giving a wrong answer.
I tested the code somewhere else, and it works fine, just wanna know where the problem is coming from and why is smallestCommons([23,18]) giving me 610722 instead of 6056820.
thanks
Your code so far
function smallestCommons(arr) {
let min = Math.min.apply(null, arr);
let max = Math.max.apply(null, arr);
let array = Array.from({length: max + 1}, (v, k) => k).slice(min)
console.log(array)
return array.reduce((x,y) => {
console.log('x = ' + x + ' y = ' + y)
let i = (x<y)?y:x;
while ( i%x != 0 || i%y != 0) i++
console.log("LCM = " + i)
return i;
});
}
console.log(smallestCommons([23,18]))
Your browser information:
User Agent is: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:65.0) Gecko/20100101 Firefox/65.0
.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/smallest-common-multiple