Created
November 16, 2016 12:19
-
-
Save jasonbellamy/2a2eace1ba7576468324d7a415000b21 to your computer and use it in GitHub Desktop.
Recursive implementation of the Collatz conjecture
This file contains 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 collatz = (x, y = 0) => { | |
if (x === 1) { | |
return y; | |
} | |
return (x % 2) ? collatz((x * 3 + 1), y + 1) : collatz((x / 2), y + 1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment