Skip to content

Commit 8fc5390

Browse files
authored
merge: FindLCM: Improve code readablility (TheAlgorithms#985)
* fix: improving code readability * fix: exchange break to return lcm * fix: fixing condition for improve readability
1 parent 4098932 commit 8fc5390

File tree

1 file changed

+4
-11
lines changed

1 file changed

+4
-11
lines changed

Maths/FindLcm.js

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,14 @@ const findLcm = (num1, num2) => {
2323
return 'Please enter whole numbers.'
2424
}
2525

26-
let maxNum
27-
let lcm
28-
// Check to see whether num1 or num2 is larger.
29-
if (num1 > num2) {
30-
maxNum = num1
31-
} else {
32-
maxNum = num2
33-
}
34-
lcm = maxNum
26+
// Get the larger number between the two
27+
const maxNum = Math.max(num1, num2)
28+
let lcm = maxNum
3529

3630
while (true) {
37-
if (lcm % num1 === 0 && lcm % num2 === 0) break
31+
if (lcm % num1 === 0 && lcm % num2 === 0) return lcm
3832
lcm += maxNum
3933
}
40-
return lcm
4134
}
4235

4336
export { findLcm }

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy