# Least Common Multiple

Hello guys,
so this is my solution to the Smallest Common Multiple problem, wanted to check if it has any kind of optimization issues(just wanna learn more about optimizing my code), it does work but none of the solutions by camperBot looked like mine, which was weird cause i always find some similarity to my code in those solutions

``````function smallestCommons(arr) {
//pre-defining variables
const rangeArr = [];
let max, min, gcd, lcm;

// This if statement defines the min and max in the range
if (arr > arr) {
max = arr;
min = arr;
} else {
max = arr;
min = arr;
}
// This loop pushes the number range into an array
for (let i = min; i <= max; i++) {
rangeArr.push(i);
}
//This function calculates the greatest common divisor
function greatestCommonDivisor(big, small) {

let remainder = (big % small);
if (remainder === 0) {
gcd = small;
return gcd;
} else {
return greatestCommonDivisor(small, remainder);
}
}
//and now we calculate the smallest common
if (rangeArr.length === 1) {
lcm = (1 * (rangeArr * rangeArr)) / greatestCommonDivisor(rangeArr, rangeArr);
} else {
lcm = (1 * (rangeArr * rangeArr)) / greatestCommonDivisor(rangeArr, rangeArr);
for (let j = 2; j < rangeArr.length; j++) {
lcm = (1 * (lcm * rangeArr[j])) / greatestCommonDivisor(lcm, rangeArr[j]);
}
}
return lcm;
}

console.log(smallestCommons([1,5]));`````````

You can ditch this to get better efficiency.

Otherwise this is basically the most efficient approach

thank you !
you’re right, i could write it without putting them into an array