Created
November 27, 2016 17:52
-
-
Save kungfux/bc56fd3f7d226a696b1ad5beaa2d05f3 to your computer and use it in GitHub Desktop.
Find smaller divisor for number
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
| export const smallestDivisor = (a) => { | |
| if (a === 1) | |
| return 1; | |
| const findDivisor = (a, d) => { | |
| if (a % d === 0) | |
| return d; | |
| else | |
| return findDivisor(a, d + 1); | |
| }; | |
| return findDivisor(a, 2); | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment