ekg / fraction.js

A fraction math library in javascript.
http://hypervolu.me/~erik/fraction.js/
165 stars 43 forks source link

Consider Euclid's method for greatest common factor #9

Closed ceautery closed 6 years ago

ceautery commented 9 years ago

You're doing a lot of unnecessary processing for finding the gcd. Consider using something like the following instead:

function gcd(a, b) { return b ? gcd(b, a % b) : a }

I think this also obviates the need for calculating the prime factors.

ceautery commented 6 years ago

Looks like something similar was implemented a couple weeks after I opened this. Closing!