I can't seem to move on from the: RangeError: Maximum call stack size exceeded
error. I am trying to find the smallest number that is evenly divisible by all numbers within a range. The numbers in that range are passed on to the function as an array.
function smallestNumberEvenlyDivisible(smallest, numbers) {
var z = 0;
for (z; z < numbers.length; z++) {
if (smallest % numbers[z] !== 0) {
smallest += smallest;
return smallestNumberEvenlyDivisible(smallest, numbers);
}
}
return smallest;
}
smallestNumberEvenlyDivisible(2018940, [18, 19, 20, 21, 22, 23]);
I expect the output to be: 6056820
but obviously is not, because of the stack error.
Pretty much ran out of ideas. Any suggestions please?