Critiquing my logic on the Smallest Common Multiple challenge

Tell us what’s happening:
So, here is an attempt at the first part of the challenge. Would anyone mind giving me a critique of my logic? Here it is:
I’m trying to use the inequality of i and j to push the loop forward, thinking that when they become equal that would mean that I’d found the LCM because it would have stopped the loop at the first value that both i and j equaled. Considering that one is lesser than the other, that value would be, logically, the smallest common multiple.

I know there’s something up with it, but I can’t see it right now.

Your code so far


function smallestCommons(arr) {
  let result = [];;
  let first = arr[0];
  let second = arr[1];
  let i, j;
for(i = first; i !== j; i++){
  first + first;
  for(j = second; j !== i; j++){
    second + second;
    if(i===j){
      result.push(i)
    }
  }
} 
  return arr;
}


smallestCommons([23,18]);

//find the smallest shared multiple of each value

Your browser information:

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

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

A few things:

  1. Fundamental: I don’t think you understood the assignment.
    1. smallestCommons([1, 5]) should be the LCM of [1, 2, 3, 4, 5], which is 60.
  2. Wasted operations: You have two additions whose return values (the results of the additions) aren’t being stored anywhere. first + first and second + second. What was the goal here?
  3. You’re returning arr, not result, which I doubt you intended.
    1. Even if you did return an array with one number in it, that’s the wrong type of value. You should be returning a number, not an array of one element which is a number.
  4. Style: Your assignments could be cleaner.
    1. let [first, second] = arr;
    2. for (let i=0; ....) and for (let j=0'....)