Skip to content

Instantly share code, notes, and snippets.

Created July 31, 2016 19:46
Show Gist options
  • Save anonymous/e59f159a268f21413445c890193e9c13 to your computer and use it in GitHub Desktop.
Save anonymous/e59f159a268f21413445c890193e9c13 to your computer and use it in GitHub Desktop.
https://repl.it/CQzb/229 created by sethopia
/*
FIBONACCI
Create a function that takes a number n and returns the nth number in the Fibonacci sequence.
The Fibonacci sequence is a series of numbers, where each number is the sum of the two numbers preceding it.
Ex)
1, 1, 2, 3, 5, 8, 13, 21, 34, 55....
*/
var fib = function(n) {
if (n === 1 || n === 2) return 1
else return fib(n - 1) + fib(n - 2)
}
console.log(fib(10));
Native Browser JavaScript
55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment