From 7938db7e476ad26cd88b640046467d44c5fedc65 Mon Sep 17 00:00:00 2001 From: CarlosZoft Date: Tue, 19 Apr 2022 15:49:07 -0300 Subject: [PATCH 1/3] fix: improving code readability --- Maths/FindLcm.js | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/Maths/FindLcm.js b/Maths/FindLcm.js index 0d09a7affb..9ef6fecfd9 100644 --- a/Maths/FindLcm.js +++ b/Maths/FindLcm.js @@ -23,18 +23,12 @@ 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) && !(lcm % num2)) break lcm += maxNum } return lcm From 589d281a2a311f4faef65ed2872318e97e330ac3 Mon Sep 17 00:00:00 2001 From: CarlosZoft Date: Tue, 19 Apr 2022 15:51:46 -0300 Subject: [PATCH 2/3] fix: exchange break to return lcm --- Maths/FindLcm.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Maths/FindLcm.js b/Maths/FindLcm.js index 9ef6fecfd9..01ac110e25 100644 --- a/Maths/FindLcm.js +++ b/Maths/FindLcm.js @@ -28,10 +28,9 @@ const findLcm = (num1, num2) => { let lcm = maxNum while (true) { - if (!(lcm % num1) && !(lcm % num2)) break + if (!(lcm % num1) && !(lcm % num2)) return lcm lcm += maxNum } - return lcm } export { findLcm } From ad3b0e6a719748f9724348b82a0e223d0a2b507c Mon Sep 17 00:00:00 2001 From: CarlosZoft Date: Wed, 20 Apr 2022 11:56:39 -0300 Subject: [PATCH 3/3] fix: fixing condition for improve readability --- Maths/FindLcm.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Maths/FindLcm.js b/Maths/FindLcm.js index 01ac110e25..101da8565a 100644 --- a/Maths/FindLcm.js +++ b/Maths/FindLcm.js @@ -28,7 +28,7 @@ const findLcm = (num1, num2) => { let lcm = maxNum while (true) { - if (!(lcm % num1) && !(lcm % num2)) return lcm + if (lcm % num1 === 0 && lcm % num2 === 0) return lcm lcm += maxNum } } 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