From 335db95b1f45a9cad67a6061992216eb9bc43e25 Mon Sep 17 00:00:00 2001 From: Sirendra <51412551+Sirendra@users.noreply.github.com> Date: Tue, 26 Oct 2021 18:54:34 +0700 Subject: [PATCH] Update 14-smallest-common-multiple.js Added simpler solution --- .../14-smallest-common-multiple.js | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/Javascript Algorithms And Data Structures Certification/Intermediate Algorithm Scripting/14-smallest-common-multiple.js b/Javascript Algorithms And Data Structures Certification/Intermediate Algorithm Scripting/14-smallest-common-multiple.js index 6455942..85dfadc 100644 --- a/Javascript Algorithms And Data Structures Certification/Intermediate Algorithm Scripting/14-smallest-common-multiple.js +++ b/Javascript Algorithms And Data Structures Certification/Intermediate Algorithm Scripting/14-smallest-common-multiple.js @@ -59,3 +59,32 @@ const findGCD=(num1,num2)=>{ } console.log(smallestCommons([1,5])); + +/* +Simpler solution + +function smallestCommons(arr) { + var loop=true + var maxNum=arr[0]>arr[1]?arr[0]:arr[1]; + var minNum=arr[0]>arr[1]?arr[1]:arr[0]; + + var counter=maxNum*2; + while(loop){ + var checker=0 + for(let i=minNum;i<=maxNum;i++){ + if(counter%i==0){ + checker+=1; + } + else {break} + } + if(checker==maxNum-minNum+1){ + loop=false; + }else{ + counter+=1; + } + + } + return counter; +} +console.log(smallestCommons([5,1])); +*/