how to find hcf of 2 numbers in javascript

Solutions on MaxInterview for how to find hcf of 2 numbers in javascript by the best coders in the world

showing results for - "how to find hcf of 2 numbers in javascript"
Maxence
07 Feb 2020
1var a = userInput[0].split(" ").map(Number)
2while(a[0] != a[1])
3{
4    if(a[0] > a[1]) { 
5        a[0] = a[0] - a[1];
6    }
7    else {
8        a[1] =a[1] - a[0]; 
9    }
10}
11console.log(a[0])