Skip to content

Instantly share code, notes, and snippets.

@kenduigraha
Created December 30, 2016 06:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kenduigraha/08be55a4cc6a38b74e10df78f74e8ea7 to your computer and use it in GitHub Desktop.
Save kenduigraha/08be55a4cc6a38b74e10df78f74e8ea7 to your computer and use it in GitHub Desktop.
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