Created
December 30, 2016 06:18
-
-
Save kenduigraha/08be55a4cc6a38b74e10df78f74e8ea7 to your computer and use it in GitHub Desktop.
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){ | |
if(n === 1){ | |
return [0] | |
}else{ | |
var s = fibonacci(n-1) | |
s.push(s[s.length - 1] + ((s.length === 1) ? 1 : s[s.length - 2])) | |
return s; | |
} | |
} | |
// 0 1 1 2 3 5 8 13 21 34 | |
console.log(fibonacci(10)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment