Skip to content

Instantly share code, notes, and snippets.

@zfdesign
Last active August 29, 2015 14:05
Show Gist options
  • Select an option

  • Save zfdesign/55a75a19ae0611c6414a to your computer and use it in GitHub Desktop.

Select an option

Save zfdesign/55a75a19ae0611c6414a to your computer and use it in GitHub Desktop.
Task: write a function called GCD that prints the greatest common divisor of two positive integers (a and b).
/* Task:
// Write a function called GCD
// that prints the greatest common divisor of two positive integers (a and b).
// */
function GCD(a,b) {
'use strict';
var calc = function (a,b) {
return (a % b === 0) ? b : null;
},
result = (a > b) ? calc(a,b) : calc(b,a);
return result;
}
// GCD(32,128);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment