Created
December 22, 2022 18:54
-
-
Save ozansulukpinar/46c7b1f6041bc289a4e8d866fb791bed to your computer and use it in GitHub Desktop.
A solution for Divisor Algorithm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This script finds the greatest common divisor of two numbers | |
function findGreatestCommonDivisor(a, b){ | |
var divisor = 1; | |
if(a < 0) | |
a *= -1; | |
if(b < 0) | |
b *= -1; | |
if(a < b) { | |
var temp = b; | |
b = a; | |
a = temp; | |
} | |
var remainder = b; | |
while(remainder > 0){ | |
remainder = a % b; | |
if(remainder == 0){ | |
divisor = b; | |
break; | |
} | |
else{ | |
a = b; | |
b = remainder; | |
} | |
} | |
return divisor; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment