Value returned not the same as instructed

I have passed the challenge but this instruction smallestCommons([23, 18]); should return 6056820 instead of 910308

function smallestCommons(arr) {
const numArr = arr;
let numIndex = 1;

numArr.map((number, index) => {
  let arrMax = Math.max(...numArr);
  const arrMin = Math.min(...numArr);
  while (arrMax > arrMin) {
    if (!numArr.includes(arrMax - 1)) {
      numArr.push(arrMax - 1);
    }
    arrMax--;
  }
});

numArr.sort((a, b) => {
  return a - b;
});

let numEvery = numArr.every(number => numIndex % number === 0);
while (!numEvery) {
  numEvery = numArr.every(number => numIndex % number === 0);
  if (numEvery) {
    break;
  }
  numIndex++;
}

return numIndex;
}

console.log(smallestCommons([23, 18])); //910308

Challenge: Smallest Common Multiple

Link to the challenge:

Where are you seeing this?

The last of the six instructions in the challenge “Smallest Common Multiple”.

smallestCommons([1, 5]) should return a number.

smallestCommons([1, 5]) should return 60.

smallestCommons([5, 1]) should return 60.

smallestCommons([2, 10]) should return 2520.

smallestCommons([1, 13]) should return 360360.

smallestCommons([23, 18]) should return 6056820.

Edit: Though now the console.log is giving me a different number. Does this have anything to do with the warning message of a possible infinite loop in my While block?

I think I am not understanding the problem. I just tested your code and it passed with flying colors. Your code also returns 6056820 for the range [23, 18]. So I’m not sure where you are getting the number 910308.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.