-
-
Save stefanmaric/27b1e5bd3e4be13b410fef6f9a6847ef to your computer and use it in GitHub Desktop.
This file contains 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
'use strict' | |
const LIMIT = 45 | |
let countA | |
let countB | |
function fibA (n) { | |
countA++ | |
return n <= 2 ? 1 : fibA(n - 1) + fibA(n - 2) | |
} | |
function fibB (n, current = 0, next = 1) { | |
countB++ | |
return n ? fibB(n - 1, next, current + next) : current | |
} | |
console.log(`N\t fibB\t fibA`) | |
for (let i = 1; i <= LIMIT; i++) { | |
countA = 0 | |
countB = 0 | |
fibA(i) | |
fibB(i) | |
console.log(`${i}\t ${countB.toString(10)}\t ${countA.toString(10)}`) | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment