Created
July 31, 2016 19:46
-
-
Save anonymous/e59f159a268f21413445c890193e9c13 to your computer and use it in GitHub Desktop.
https://repl.it/CQzb/229 created by sethopia
This file contains hidden or 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
/* | |
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)); |
This file contains hidden or 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
Native Browser JavaScript | |
55 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment