hi guys.
was trying to solve a gcd and scm code challenge but didnt seem to get it.So I saw this code online but dont seem to understand what the gcd and scm functions are doing or even what the a and b parameters are
function smallestCommons(arr) {
var max = Math.max(...arr),
min = Math.min(...arr),
range = [],
scm; // smallestCommonMultiple
for (var i = min; i <= max; i++) {
range.push(i);
}
function gcd(a, b) { // greatestCommonDivisor based on Euclid's Algorithm
var answer;
for (var x = 0; x <= a; x++) {
if(a % x === 0 && b % x === 0)
answer = x;
}
return answer;
}
function lcm(a, b) { // leastCommonMultiple based on Euclid's Algorithm
return (a * b) / gcd(a, b);
}
scm = range.reduce(lcm);
return scm; // smallestCommonMultiple
}
smallestCommons([23, 18]);