merge: FindLCM: Improve code readablility (#985)

* fix: improving code readability

* fix: exchange break to return lcm

* fix: fixing condition for improve readability
This commit is contained in:
Carlos Rafael
2022-04-20 12:59:29 -03:00
committed by GitHub
parent 40989326f1
commit 8fc53906e6

View File

@ -23,21 +23,14 @@ const findLcm = (num1, num2) => {
return 'Please enter whole numbers.'
}
let maxNum
let lcm
// Check to see whether num1 or num2 is larger.
if (num1 > num2) {
maxNum = num1
} else {
maxNum = num2
}
lcm = maxNum
// Get the larger number between the two
const maxNum = Math.max(num1, num2)
let lcm = maxNum
while (true) {
if (lcm % num1 === 0 && lcm % num2 === 0) break
if (lcm % num1 === 0 && lcm % num2 === 0) return lcm
lcm += maxNum
}
return lcm
}
export { findLcm }