# Programación de algoritmos intermedios - Mínimo común múltiplo

### Cuéntanos qué está pasando:

Hello, this code does not pass the test, I suppose it is because of recursion and that it does not work in large numbers, how can I correct this? or you can’t use recursion

### Tu código hasta el momento

``````function smallestCommons(arr) {

let rango = [];
let min = Math.min(...arr);
let max = Math.max(...arr);
let acumu = 1;

for (let i = max; i >= min; i--) {rango.push(i);}
console.log(rango)

function recurs(maxM, arrRan, rec) {

let result = maxM*rec

console.log(result)
if (arrRan.every(arreglo => result % arreglo === 0)) {
return result;
} else {
return recurs(maxM,arrRan, rec+1);
}
}
return recurs(max, rango, acumu);

}

console.log(smallestCommons([1,5]));
``````

El agente de usuario es: `Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36`

### Información del Desafío:

Programación de algoritmos intermedios - Mínimo común múltiplo

The function doesn’t need recursion. A `for` loop could easily work here. You need to multiple the numbers together so you can get a number divisible by them all.

So you recommend not using recursion throughout the exercises? because this code technically passes the tests but due to overflow it does not. Should I practically forget about recursion?

No. Recursion has it’s uses. It can make hard problems simpler. But it can make problems harder if done wrong.

And as for your code, I couldn’t actually tell. It looks like a little complicated and you probably aren’t reaching your recursion return condition.

Can you tell me what your code is trying to do?

The code basically puts the range of numbers in an array, then takes the largest number and multiplies it by 2, 3, 4, etc. until that number can be divisible with the rest of the numbers in the array.

The code passes the first 4 tests, the last 2 fails.