Skip to content

Instantly share code, notes, and snippets.

@abalogun
Created August 27, 2016 04:19
Show Gist options
  • Save abalogun/d0b44dd1a4a1c861c9a9d55158f75c74 to your computer and use it in GitHub Desktop.
Save abalogun/d0b44dd1a4a1c861c9a9d55158f75c74 to your computer and use it in GitHub Desktop.
function fib(n){
var fib = [];
fib[0] = 1;
fib[1] = 1;
for(var i =2, i <= n; i++) {
fib[i] = fib[i - 1] + fib[i-2];
}
return fib[i];
}
@glenwperry
Copy link

finally figured this one out (but my expressions look pretty crazy). the hint is: get the sequence started manually to avoid infinite loop, use your loop to .push items to your array, and then instead of using integers, use references to the numbers (by index of your new array ex: newArray[newArray.length - 1]) in your new array.

this one was really hard for me. if you want to see my solution let me know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment