Skip to content

Instantly share code, notes, and snippets.

@ozansulukpinar
Created December 22, 2022 18:54
Show Gist options
  • Save ozansulukpinar/46c7b1f6041bc289a4e8d866fb791bed to your computer and use it in GitHub Desktop.
Save ozansulukpinar/46c7b1f6041bc289a4e8d866fb791bed to your computer and use it in GitHub Desktop.
A solution for Divisor Algorithm
// 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