From 8fc53906e63afc981633bfafc47752004441bac7 Mon Sep 17 00:00:00 2001 From: Carlos Rafael Date: Wed, 20 Apr 2022 12:59:29 -0300 Subject: [PATCH] merge: FindLCM: Improve code readablility (#985) * fix: improving code readability * fix: exchange break to return lcm * fix: fixing condition for improve readability --- Maths/FindLcm.js | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/Maths/FindLcm.js b/Maths/FindLcm.js index 0d09a7aff..101da8565 100644 --- a/Maths/FindLcm.js +++ b/Maths/FindLcm.js @@ -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 }