I get an error:

“Maximum call stack size exceeded”

There is a recursive function.

It has a base and a termination point.

But it seems they don’t work.

Is there a chance for this code?

Please help.

After the comment of ArielLeslie(totally not a bot)

I modified the code:

And now the code checks if all the elements

have the same smallest perfect divisor, and it comes to a point,

where all elements return true.

The problem is that it doesn’t stop the iteration.

There is an `iterate boolean`

, which turns to false at the end, but then at the beginning it gets assigned to true again.

Is there a way to fix that?

Or is there another way to make this work?

The code below is set to iterate 8 times. That’s the point where it should stop. If set to 9, it just goes on.

When the problem will be fixed the hard coded for loop will be changed to `while (iteration)`

, if that’s OK.

```
function smallestCommons(arr) {
arr.sort();
// get the numbers between the two elements
let numbers = [];
let secondElement = arr[1];
for (var i = 0; i < secondElement; i++) {
numbers.push(arr[1]--);
}
function findCommon(arr) {
let multiplier = arr[0]++;
let multiplies = [];
let booleans = [];
// multiply all elements with multiplier
// and store the values in multiplies
for (var i = 0; i < arr.length; i++) {
multiplies.push(arr[i] * multiplier);
multiplier++;
}
// check which elements of the multiplies
// array have a perfect division
// with the first element
// of the multiplies array
// and push the boolean results in a array,
for (var i = 0; i < multiplies.length; i++) {
booleans.push(multiplies[i] % arr[0] === 0);
}
// count the elements that are true
let trueValues = 0;
for (var i = 0; i < booleans.length; i++) {
if (booleans[i] === true) {
trueValues++
}
}
// if all elements are true
// return the first element.
if (trueValues === arr.length) {
return multiplies[0];
}
// repeate the process
// until all elements are true
// This seems like a double check.
if (trueValues < arr.length) {
findCommon(arr);
}
console.log(multiplies);
console.log(booleans);
console.log(trueValues);
}
let result = findCommon(numbers);
return result;
}
smallestCommons([1, 5]);
```

**Your browser information:**

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

.

**Link to the challenge:**

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