Skip to content

Instantly share code, notes, and snippets.

@iamamit-107
Created May 9, 2020 16:12
Show Gist options
  • Save iamamit-107/739ab730b119349138c9df7de17d4553 to your computer and use it in GitHub Desktop.
Save iamamit-107/739ab730b119349138c9df7de17d4553 to your computer and use it in GitHub Desktop.
function fib(n) {
const result = [0, 1];
for (let i = 2; i <= n; i++) {
let a = result[i - 1];
let b = result[i - 2];
result.push(a + b);
}
return result[n];
}
console.log(fib(7));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment