Tell us what’s happening:
Hello, i’m trying to achieve the Smallest Common Multiple challenge. I found a way to find the Smallest common multiple of two numbers, but i don’t know how to do this with a range. Someone can help me ? Thank’s.
Your code so far
function smallestCommons(arr) {
// division parts
let dividend = Math.max(arr[0],arr[1]);
let divisor = Math.min(arr[0],arr[1]);
let between = [];
let quotient = Math.floor(dividend/divisor);
let remainder = dividend % divisor;
// sCM = smallest common multiple
let sCM = 0;
// gCD = greatest common divisor
let gCD = 0;
// this function returns Greather Common Divisor of two numbers
function GCD(dividend,divisor){
while (remainder != 0){
dividend = divisor;
divisor = remainder;
remainder = dividend % divisor;
}
return divisor
}
// this function returns numbers between the min and max range
for ( let i = dividend; i >= divisor; i--){
between.push(i);
}
gCD = GCD(dividend,divisor)
sCM = (dividend * divisor)/gCD
console.log(sCM)
// is not defined yet
return result
}
smallestCommons([210,45]);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36
.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/smallest-common-multiple