Smallest Common Multiple | Wrong validation to running code

Tell us what’s happening:

I think the platform is evaluating my code erroneously, because my solution match all requirements but the console says:

smallestCommons([23, 18]) should return 6056820

even if the tests is passing.

Your code so far


function smallestCommons(arr) {
  let scm = 1
  const orderedArr = arr.sort((a, b) => a > b)
  const [ min, max ] = [ Math.min(...orderedArr), Math.max(...orderedArr) ]
  const quotients = [...Array(max + 1).keys()].slice(min, max + 1)
  while(true) {
    const isDivisible = quotients.every(q => scm % q === 0)
    if (isDivisible) return scm
    scm++
  } 
}

smallestCommons([23, 18])

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64; rv:69.0) Gecko/20100101 Firefox/69.0.

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

I think you are probably right, because on the new public beta platform (notice: .dev TLD) your code passes all tests:

https://www.freecodecamp.dev/learn/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/smallest-common-multiple

1 Like