@ParasArora/

least common multiple (LCM)

Nodejs

No description

fork
loading
Files
  • index.js
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
function gcdRec(a, b){
  if(b == 0) return a;
  return gcdRec(b, a % b);
}

function lcm(a, b){
  /* 
    FORMULA:
    lcm(a, b) x hcf(a, b) = a x b;
    
  */
  return (a * b) / gcdRec(a, b);
}

lcm(4, 6);
node v10.16.0