mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-07-04 15:39:42 +08:00
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:
@ -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 }
|
||||
|
Reference in New Issue
Block a user