Thank you guys. Very constructive comments.
I was aware that my algorithm is not that efficient, I did not look up the math formula for this task. I wanted to see if I am able to come up with a solution of my own.
Based on your comments, I have made some small corrections to my code, but still I had to use the “// noprotect” to be able to pass the tests.
function smallestCommons(arr) {
arr = arr.sort((a,b) => a-b);
var len = arr[1] - arr[0] + 1;
var cmmd = arr[arr.length - 1] * arr[arr.length - 1];
var rangeArr = [];
for (var i = 0; i < len; i++) {rangeArr.push(arr[0] + i);}
var tester = true;
while (tester) {
cmmd ++;
tester = !rangeArr.every(x => cmmd % x == 0);
}
return cmmd;
}
smallestCommons([1,5]);
Thanks a lot and keep up with your comments. It helps a lot a beginner like me