Skip to content

Instantly share code, notes, and snippets.

@jukben
Last active June 5, 2017 14:45
Show Gist options
  • Save jukben/609439dc85244e1d761ed85f6f208119 to your computer and use it in GitHub Desktop.
Save jukben/609439dc85244e1d761ed85f6f208119 to your computer and use it in GitHub Desktop.
Fib
// using iteration
const fib = (number) => {
const results = [0, 1]
for (let i = 0; i <= number - 2; i++){
results[i+2] = results[i+1] + results[i];
}
return results[number];
}
// using recursion (be aware of stack overflow :neckbeard:)
const fib = (number) => {
if (number<2) return number
return fib(number - 2) + fib(number - 1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment