Last active
March 29, 2017 14:38
-
-
Save ChillyBwoy/b3e95b266f8eaba3e6f9 to your computer and use it in GitHub Desktop.
fn with acc
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
function fibonacci (n) { | |
const fn = (n, a, b) => n === 0 ? a : fn(n - 1, a + b, a); | |
return fn(n, 0, 1); | |
}; | |
function factorial (n) { | |
const fn = (n, acc) => n === 0 ? acc : fn(n - 1, n * acc); | |
return fn(n, 1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment