Last active
October 26, 2017 00:12
-
-
Save farskid/526943fc323a1b1be31b27d35800c65a to your computer and use it in GitHub Desktop.
Log first N numbers in Fibonacci sequence in Javascript
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
function fibo(n) { | |
if (n === 1) return 0; | |
if (n === 2) return 1; | |
return fibo(n - 1) + fibo(n - 2); | |
} | |
function fiboLogger(n) { | |
if (n === 0) return []; | |
return [fibo(n)].concat(fiboLogger(n-1)); | |
} | |
console.log(fiboLogger(10).reverse()) // [0, 1, 1, 2, 3, 5, 8, 13, 21, 34] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment