Skip to content

Instantly share code, notes, and snippets.

@vshjxyz
Created November 12, 2015 12:50
Show Gist options
  • Save vshjxyz/2e3ce12f48b6e91f2299 to your computer and use it in GitHub Desktop.
Save vshjxyz/2e3ce12f48b6e91f2299 to your computer and use it in GitHub Desktop.
just a test function to see how recursive generators works in ES6
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