Problems with JS execution

Problems with JS execution
0

#1

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]));

#2

I also have that practice of trying first in the browser console. When a result does not match, I have seen that the browser console is more permissive. There does not seem to be an error in the code you are showing, however it may be something you are not showing, such as the constructor you use.


#3

Thanks I just tried another solution (without functional programming) and it works, i don’t know why this is happening, i tested my code in many online JS testers and the outcome is correct in there, well thanks anyway Yoelvis ;).