Skip to content

Commit 8fc5390

Browse files
authored
merge: FindLCM: Improve code readablility (#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

+4-11
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)