Advertisement
Btwonu

Untitled

Sep 16th, 2020 (edited)
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function GCD(x, y) {
  2.   if (y == 1) return 1;
  3.  
  4.   for (let i = 2; i <= y; i++) {
  5.     if (x % i == 0 && y % i == 0) {
  6.       //divide our numbers
  7.       x /= i;
  8.       y /= i;
  9.  
  10.       return i * GCD(x, y);
  11.     }
  12.  
  13.     //bottom of the recursion
  14.     if (i == y) {
  15.       return 1;
  16.     }
  17.   }
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement