mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-07-05 00:01:37 +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.'
|
return 'Please enter whole numbers.'
|
||||||
}
|
}
|
||||||
|
|
||||||
let maxNum
|
// Get the larger number between the two
|
||||||
let lcm
|
const maxNum = Math.max(num1, num2)
|
||||||
// Check to see whether num1 or num2 is larger.
|
let lcm = maxNum
|
||||||
if (num1 > num2) {
|
|
||||||
maxNum = num1
|
|
||||||
} else {
|
|
||||||
maxNum = num2
|
|
||||||
}
|
|
||||||
lcm = maxNum
|
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
if (lcm % num1 === 0 && lcm % num2 === 0) break
|
if (lcm % num1 === 0 && lcm % num2 === 0) return lcm
|
||||||
lcm += maxNum
|
lcm += maxNum
|
||||||
}
|
}
|
||||||
return lcm
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export { findLcm }
|
export { findLcm }
|
||||||
|
Reference in New Issue
Block a user