Tell us what’s happening:
Hi there,
I stuck in this challenge , my code accepts all tests except [23,18]
Is there something making value overflow?
Please help me
Your code so far
function smallestCommons(arr) {
let tmp = arr.sort((x,y) => x-y); //sort array low to high
let dividable = function (range, value ){//function return true if "value" accept division on all the range
for(let i= range[0]; i<=range[1];i++){
if(value % i !== 0){ return false;}
}
console.log(value);return true;
};
let result = 0;//my result variable
let stop = true;//boolean to stop looping
let i = 1;
while(stop){
if(dividable(tmp, tmp[1] * i)) {
result = tmp[1] * i;
stop = false;
}else{
i++;
}
} ;
console.log(result);
return result;
};
smallestCommons([23,18]);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.131 Safari/537.36
.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/smallest-common-multiple