Smallest Multiple: Recursive Function Only Repeats Once

Tell us what’s happening:
My code seems to be working properly, but my recursive function only repeats once regardless of the numbers I input. Running isMultiple loops through the lower numbers in the array correctly accepting them if they are multiples and the returning false when it’s not a multiple, but the second time it returns false it doesn’t seem to call the function again.

Your code so far


function smallestCommons(arr) {
//Assigns highest element to count
let count = arr[1];
// get the range of numbers
let range = Math.abs(arr[0] - arr[1]);
// Get the smaller value.
let lesser;
(arr[0] < arr[1]) ? lesser = arr[0] : lesser = arr[1];
let greater;
(arr[0] < arr[1]) ? greater = arr[1] : greater = arr[0];
console.log(greater);
let rangeArray = [];
for (let i = lesser; i <= greater; i++){
  rangeArray.push(i);
}
function isMultiple(){
  console.log(arr, count);
  for(let i = rangeArray[0]; i < range + 1; i++){
    console.log("Count" + count + "%" + i);
    if(count%i != 0) {
      //console.log(i, count)
      return false;
    }
  }
  console.log("Passes these test");
  return count;
}
if(isMultiple() === false){
  ++count;
  return (isMultiple());
}
/*if(isMultiple(count) === true){
  console.log(count);
  return count;
}*/
}
smallestCommons([1, 13]);

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36.

Challenge: Smallest Common Multiple

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

Neither of your functions are recursive.
isMultiple() gets called twice because you call it twice.

1 Like

Thanks Ariel,
I’m going too fast and just took that for granted by modeling it off of another solution that was a little different. I’ll move it inside the function itself instead of the outer function.