Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 8fc5390

Browse files
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) returnlcm
3832
lcm += maxNum
3933
}
40-
return lcm
4134
}
4235

4336
export { findLcm }

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /