Hi Team,
I have written below code to pass the ** Intermediate Algorithm Scripting: Smallest Common Multiple** in the javascript section. This code is not passing the last 2 test cases ([1,13] and [23,18]) for that problem. But when I have tested my code in Chrome console it is returning me the right result.
Can anyone tell me what is the issue with my code.
function smallestCommons(arr) {
let max = arr[0] > arr[1] ? arr[0] : arr[1];
let min = max == arr[1] ? arr[0] : arr[1];
let diff = max - min;
let end = true;
for(var i = max + 1; end === true; i++) {
var count = 0;
for(var j = min; j <= max; j++) {
if(i % j === 0) {
count += 1;
}
}
if(count == diff + 1) {
end = false;
return i;
}
}
}
smallestCommons([1,13]);
Thanks & Regards,
Shashank