Skip to content

Instantly share code, notes, and snippets.

@saknarak
Created August 21, 2018 03:53
Show Gist options
  • Save saknarak/9c09d45e36b151eed7cb3aa356f433c0 to your computer and use it in GitHub Desktop.
Save saknarak/9c09d45e36b151eed7cb3aa356f433c0 to your computer and use it in GitHub Desktop.
Fibo O(N) JavaScript
function fibo(n) {
if (n <= 2) {
return 1
}
let a = 1
let b = 1
for (let i = 3; i < n; i++) {
b = a + b
a = b - a
}
return a + b
}
for (let i = 1; i <= 10; i++) {
console.log(i, fibo(i))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment