Created
November 12, 2015 12:50
-
-
Save vshjxyz/2e3ce12f48b6e91f2299 to your computer and use it in GitHub Desktop.
just a test function to see how recursive generators works in ES6
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 *fib(iterations=10, val1=0, val2=1) { | |
if (iterations > 0) { | |
let sum = val1 + val2; | |
yield sum; | |
yield *fib(iterations - 1, val2, sum); | |
} | |
} | |
[...fib()].map((val) => console.log(val)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment