Intermediate Algorithm Smallest Common Multiple

Help please!! I don’t know what is happening because I think my code its all right, I checked in my visual studio and the answer is the same that freecodecamp requiered (smallestCommons([1, 13]) should return 360360.

  var sortedArr = arr.sort(function (a, b) {
    return a - b
  })
  var newArr = []

  for (var i = sortedArr[0]; i <= sortedArr[arr.length - 1]; i++) {
    newArr.push(i)
  }
  var condition = true
  var smallestMultiple = 0
  while (condition) {
    smallestMultiple++
    for (var j = sortedArr[0]; j <= sortedArr[arr.length - 1]; j++) {
      if (smallestMultiple % j !== 0) {
        break
      } else if (j === sortedArr[arr.length - 1]) {
        condition = false
      }
    }
  }
  return smallestMultiple
}```

If you’re algorithm fails for the hardest tests in FCC but works elsewhere, it means that the FCC test is timinh out. It means that you need to find a more efficient solution,

1 Like