Tell us what’s happening:
All of the other tests have confirmed the code is correct, but the last one (smallestCommons([23, 18])) doesnt have enough memory to complete, returning ‘RangeError: Maximum call stack size exceeded’.

Any tips on how to solve this?

Your code so far

function smallestCommons(arr) {
arr.sort(function(a,b) {
return a - b
})
let scm = arr[0]
for (let i = arr[0]; i <= arr[1]; i++) {
scm = (scm * i) / gcd(scm, i)
}
return scm
}
console.log(smallestCommons([23, 18]));
function gcd(a,b) {
if (a > b) {
return gcd(a-b, b);
} else if (a < b) {
return gcd(a, b-a);
} else {
return a
}
}

Your browser information:

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

Challenge: Intermediate Algorithm Scripting - Smallest Common Multiple