I'm working in JavaScript and I am solving for smallest common multiple, for two numbers, and the smallest common multiple has to be divisible by all numbers between the two numbers.
Right now, my code is not working at all and nothing is being returned. I had one function to calculate the smallest common multiple and a second function to determine if that multiple was divisible by the numbers between the smallest and largest number.
function smallestCommons(arr) {
var max = 0;
var min = 0;
var lcm = 0;
var max2 = 0;
if(arr[0]> arr[1]) {
max = arr[0];
min = arr[1];
} else {
max = arr[1];
min = arr[0];
}
function range(item){
for(var j = min+1; j < max; j++){
if(item % j !== 0){
return 0;
} else {
return item;
}
}
}
function lcmFind(min1, max1){
for(var i =1; i < min1; i++){
max1 = max1 * i;
if(range(max1) === 0){
continue;
} else {
return range(max1);
}
}
}
return lcmFind(min,max);
}
smallestCommons([1,5]);