Skip to content

Instantly share code, notes, and snippets.

@ChillyBwoy
Last active March 29, 2017 14:38
Show Gist options
  • Save ChillyBwoy/b3e95b266f8eaba3e6f9 to your computer and use it in GitHub Desktop.
Save ChillyBwoy/b3e95b266f8eaba3e6f9 to your computer and use it in GitHub Desktop.
fn with acc
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