Hi,
So i have been stuck on SCM - https://www.freecodecamp.org/challenges/smallest-common-multiple for some time my algo is like this -
1)Take the two number and sort then in ascending or descending order
2)Take a new array and insert all values between the 2 ranges
3)Then multiply each number in array(get their multiples) and find the first number which is common in all multiples of number-
So for 1,2,3,4,5
I know
1 like 1,2,3,4,5,6,7,8…
2 like 2,4,6,8,10,12 etc
3like 3,6,9, etc
4 like 4,8,12,16, etc
5 like 5,10,15 etc and its 60 which is first lcm …
But i do not know how to do this in program ,and create these loops …
I can only think in a simple way and not good with any complex thing …can some one please guide -
My jsfiddle link - https://jsfiddle.net/jinisner/y6dvLe50/ , thanks
function smallestCommons(arr) {
var test = [];
var x;
arr.sort(function(a,b){
return b-a;
});
for(var i = arr[0]; i >= arr[1];i--){
test.push(i);
}
console.log(test);
// console.log(test);
return arr;
}
smallestCommons([1,5]);