Last active
December 12, 2023 09:32
-
-
Save Celestz/53728451d9920ce12b420904eee6eb3d to your computer and use it in GitHub Desktop.
Fib Straight forward
This file contains hidden or 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
// 0 1 1 2 3 5 8 13 21 34 | |
function fibValue(index) { | |
let [prev, next] = [0, 1] | |
if (index < 2) { | |
return index | |
} | |
for (var x = 2; x < index; x++) { | |
const result = prev + next | |
prev = next | |
next = result | |
} | |
return prev + next | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment