Need help with Smallest Common Multiple

Need help with Smallest Common Multiple
0

#1

Hello,

I need some help with this code. I’m not sure why stopping before getting the expected results.

function smallestCommons(arr) {
var mayor = Math.max.apply(null,arr);
var menor = Math.min.apply(null,arr);
var i=mayor;
var newArr = [];
for (i; i >= menor; i–) {
newArr.push(i);
}
//console.log(newArr);
i=1;
var mcm=0;
var h;
do{
mcm = mayormenori;
for (h=2; h<newArr.length;h++){
if (mcm%newArr[h] !==0){
break;
}
}i++;
}while(h !== newArr.length);
//console.log(mcm);
return mcm;
}

smallestCommons([1,5]);


#2

change mcm = mayormenori; … to … mcm = newArr[0]*newArr[1]*i;
put a multiply sign inbetween newArr[0] …newArr[1] …i … as its not showing up when i post


#3

It’s not working either.

I tried with your code mcm = arr[0]*arr[1]*i; and it doesn’t work.


#4

it works here … have another look


#5

Yes, it is.
Thank you again.