Last active
April 12, 2019 06:43
-
-
Save gaoryrt/4472c95fe26f393032ed22d04dd8d609 to your computer and use it in GitHub Desktop.
fibArr of length num
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 sumOfPrev = arr => { | |
let len = arr.length | |
return arr[len - 1] + arr[len - 2] | |
} | |
const fib = num => { | |
if (num === 1) return [1] | |
else if (num === 2) return [1, 1] | |
else { | |
const prev = fib(num - 1) | |
return prev.concat(sumOfPrev(prev)) | |
} | |
} | |
console.log(fib(8)) |
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 Y = f => (x => f(x(x)))(x => f((...y) => x(x)(...y))) | |
const sumOfPrev = arr => { | |
let len = arr.length | |
return arr[len - 1] + arr[len - 2] | |
} | |
const fib = Y( | |
f => num => { | |
if (num === 1) return [1] | |
else if (num === 2) return [1, 1] | |
else { | |
const prev = f(num - 1) | |
return prev.concat(sumOfPrev(prev)) | |
} | |
} | |
) | |
console.log(fib(8)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment