smallestCommons([23, 18]) should return 2018940 and not 6056820 as the last test states

The last test shows that smallestCommons([23, 18]) should return 6056820, even though it should return 2018940.

My code:

function smallestCommons(arr) {
let dividingArray = [];
for(let i = Math.min(...arr)+ 1; i < Math.max(...arr);i++){

let answerReached = false;
for(let i = arr[0] * arr[1];answerReached == false;i+= Math.max(...arr)){
if(dividingArray.every(val => i%val == 0) == true){
var answer = i;
answerReached = true;
return answer;
console.log(smallestCommons([23, 18]));
  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.80 Safari/537.36 Edg/98.0.1108.50

Challenge: Smallest Common Multiple

Link to the challenge:

What is your basis for that?

You have an error in your code. Log out your dividingArray and confirm that it is what it should be. It is working by accident in the other cases, for math reasons.

When I fix that error in your dividingArray, your code passes all the tests.

maths says that 2018940 is not a multiple of 18

1 Like

Thank you very much.

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