Skip to content

Instantly share code, notes, and snippets.

@stefanmaric
Created March 6, 2017 22:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stefanmaric/27b1e5bd3e4be13b410fef6f9a6847ef to your computer and use it in GitHub Desktop.
Save stefanmaric/27b1e5bd3e4be13b410fef6f9a6847ef to your computer and use it in GitHub Desktop.
'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