Hi All,
Im trying to pass the challange " Smallest Common Multiple" I always develop the solution in a snippet at chrome (much easier to debug) i’m getting the correct result in there (testing all the cases) but when i tried to run the test in the freecodecamp throws this:
// running tests
smallestCommons([1, 13]) should return 360360.
smallestCommons([23, 18]) should return 6056820.
// tests completed
but in the snippet in chrome all the results for that cases are correct:
I can change the approach and try with something else but i have curious, why this happen? any clue would be great. This is the code that I made:
function smallestCommons(arr) {
let minor = (arr[0]<arr[1])?arr[0]:arr[1];
let rangeArr = new Int8Array(((arr[0]<arr[1])?arr[1]-arr[0]:arr[0]-arr[1])+1);
let commomMul = 0;
let filterArr = [];
while(filterArr.length != rangeArr.length){
commomMul++;
filterArr = rangeArr.filter((val,i)=>{
return (commomMul%(i+minor))==0;
})
}
return commomMul;
}
console.log(smallestCommons([1,13]));
console.log(smallestCommons([23,18]));