Last active
November 27, 2016 17:52
-
-
Save kungfux/572f4ea33049e4f9b3abcf7f8095078a to your computer and use it in GitHub Desktop.
Find bigger common divisor for two numbers
This file contains hidden or 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
| const biggerCommonDivisor = (a, b) => { | |
| const findDivisor = (a, b, z) => { | |
| console.log(z); | |
| if (a % z === 0 && b % z === 0) | |
| return z; | |
| else | |
| return findDivisor(a, b, z - 1); | |
| }; | |
| if (b > a) | |
| return findDivisor(b, a, b); | |
| else | |
| return findDivisor(a, b, a); | |
| }; | |
| export default biggerCommonDivisor; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment