Tell us what’s happening:
Can you help me avoid reaching the max call stack?
When I log to the console it seems to be exceeding the maximum call stack size.
I have an if statement checking that every item in the array meets the correct condition else j counting up by 1 each time and recusing.
I can pass all tests except the last two which need to reach higher numbers than the console is allowing. I also tried adding the highest number in the array to J to count up faster but it still isn’t arriving before max is reached.
// running tests
smallestCommons([1, 13]) should return 360360.
smallestCommons([23, 18]) should return 6056820.
// tests completed
Your code so far
function smallestCommons(arr) {
arr.sort(function(a, b){return a-b});
let array = [];
for (let i = arr[0]; i <= arr[1]; i++){
array.push(i)
}
let j = 1
function checkMult(arr) {
if (arr.every( test => (Number.isInteger(j / test)))) {
//console.log(j);
return j
} else {
j++;
checkMult(array);
}
}
checkMult(array);
//console.log(j);
return j;
}
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/87.0.4280.88 Safari/537.36
.
Challenge: Smallest Common Multiple
Link to the challenge: