forked from TheAlgorithms/JavaScript
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEucledianGCD.js
More file actions
Latest commit
30 lines (28 loc) · 742 Bytes
/
Copy pathEucledianGCD.js
File metadata and controls
30 lines (28 loc) · 742 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
functioneuclideanGCDRecursive(first,second){
/*
Calculates GCD of two numbers using Euclidean Recursive Algorithm
:param first: First number
:param second: Second number
:return: GCD of the numbers
*/
if(second===0){
returnfirst
}else{
returneuclideanGCDRecursive(second,(first%second))
}
}
functioneuclideanGCDIterative(first,second){
/*
Calculates GCD of two numbers using Euclidean Iterative Algorithm
:param first: First number
:param second: Second number
:return: GCD of the numbers
*/
while(second!==0){
consttemp=second
second=first%second
first=temp
}
returnfirst
}
export{euclideanGCDIterative,euclideanGCDRecursive}