Smallest Common Multiple javascript challenges

Tell us what’s happening:
Can someone take a look at my code, all but the last test are passing.
I thought my logic was sound on this one.

Your code so far


function smallestCommons(arr) {
  if (arr[1] < arr[0]) {
    arr.reverse();
  }
  var commonArr = []
  // populate array
  for (let i = arr[0]; i <= arr[1]; i++) {
      commonArr.push(i);
  }
  // truncate array so you just get top half of numbers
  commonArr.splice(0,commonArr.length/2);

// start searching for highest multiple
  var multiple = 2
  var highestFound = false
  while(!highestFound){
    var highest = commonArr[commonArr.length-1] * multiple;
    highestFound = commonArr.every((element) => highest % element === 0 )
    // if not also even
    if(highest % 2 !== 0){
      highestFound = false;
    }
    multiple++;
  }
  return highest;
}


smallestCommons([1, 5]);

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/smallest-common-multiple

I could pass the tests by commenting out this line:

// commonArr.splice(0,commonArr.length/2);
2 Likes