Skip to content

Instantly share code, notes, and snippets.

@jafow
Last active October 11, 2015 14:43
Show Gist options
  • Save jafow/26c802c4244dbb39af41 to your computer and use it in GitHub Desktop.
Save jafow/26c802c4244dbb39af41 to your computer and use it in GitHub Desktop.
Euclid's Algorithm on JavaScript

####What's the greatest common divisor of two numbers?

'use strict';

let euclid = (int1, int2) {
  
  if(int1 === int2)
    return int1;

  if(int1 > int2)
    return euclid((int1-int2), int2);

  else
    return euclid(int1, (int2 - int1));
}

This is the OG version. It runs slow when there's a large difference between int1 and int2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment