Smallest Common Multiple problem

Smallest Common Multiple problem
0

#1

Tell us what’s happening:
Hey, I’am stuck on Smallest Common Multiple. I got a sorted array, then got all necessary numbers from it and now I’m trying to check it for multiple ‘x’ it fails. Could you pls give me a hint on why is it happening?

Your code so far

  var allNums = [];
  var end = [];
  arr = arr.sort();
  for (var i=arr[0]; i<=arr[1]; i++) {
    allNums.push(i);
  }
  allNums.forEach(function (elem, index){ //strange behaviour
    for (var x=0; x<100;x++) {
       if (elem%x === 0) {
        end.push(x);
       }
       else end.push(false); //just for checks
        }
     }); 
  return end; 
}

smallestCommons([1,5]);```
**Your browser information:**

Your Browser User Agent is: ```Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.79 Safari/537.36```.

**Link to the challenge:**
https://www.freecodecamp.org/challenges/smallest-common-multiple

#2

Why are you checking for multiples of every number between 0 and 100?


#3

Because I know that 1,2,3,4 and 5 have smallest common multiple 60 and I don’t want JS to do much extra work. And what do you suggest?