Created
July 25, 2017 06:21
-
-
Save doug-numetric/97d874d74a2135f2a3b0dd3b73d99947 to your computer and use it in GitHub Desktop.
Efficient fibonacci calculator without loops or recursion
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
const { reduce, range, map } = require('lodash/fp') | |
const fibinacci = | |
num => reduce( | |
acc => [ | |
acc[0] + acc[1], | |
acc[0] | |
], | |
[1,0], | |
range(0, num) | |
)[0]; | |
console.log(map(e => fibinacci(e), [1,2,3,4,5,6,7,8,9])); | |
// [ 1, 2, 3, 5, 8, 13, 21, 34, 55 ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment