Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function GCD(x, y) {
- if (y == 1) return 1;
- for (let i = 2; i <= y; i++) {
- if (x % i == 0 && y % i == 0) {
- //divide our numbers
- x /= i;
- y /= i;
- return i * GCD(x, y);
- }
- //bottom of the recursion
- if (i == y) {
- return 1;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement