Tell us what’s happening:
Help me with explanation or help me find where am i wrong. The below 3 cases test fails.
smallestCommons([2, 10])
should return 2520.
smallestCommons([1, 13])
should return 360360.
smallestCommons([23, 18])
should return 6056820.
THANKS in advance
Your code so far
function smallestCommons(arr) {
var r = arr.sort();
var arr1 = [];
for(var i = arr[0];i<= arr[arr.length-1];i++) {
arr1.push(i);
}
var x = true;
var lcm = 0;
while(x) {
lcm++;
for(var j = arr1[0];j <= arr1[arr1.length-1];j++) {
if(lcm % j !== 0) {
break;
}
else if(j === arr1[arr1.length-1]) {
x = false;
}
}
};
//console.log(lcm);
return lcm;
}
smallestCommons([2,10]);
Your browser information:
User Agent is: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:67.0) Gecko/20100101 Firefox/67.0
.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/smallest-common-multiple/