Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ethagnawl/es6-generators-fibonacci
Proof of concept for Wikipedia article on generators.
https://github.com/ethagnawl/es6-generators-fibonacci
Last synced: about 2 months ago
JSON representation
Proof of concept for Wikipedia article on generators.
- Host: GitHub
- URL: https://github.com/ethagnawl/es6-generators-fibonacci
- Owner: ethagnawl
- Created: 2015-01-11T03:24:06.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2015-01-11T03:39:31.000Z (about 10 years ago)
- Last Synced: 2024-10-14T19:07:53.541Z (3 months ago)
- Language: JavaScript
- Homepage:
- Size: 133 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Example used in [Wikipedia article on generators](https://en.wikipedia.org/w/index.php?title=Generator_(computer_programming)#ECMAScript).
function* fibonacci() {
let init = 1;
let [prev, curr] = [0, init];
yield init;
while (true) {
[prev, curr] = [curr, prev + curr];
yield curr;
}
}
var gen = fibonacci();
console.log(gen.next().value); // 1
console.log(gen.next().value); // 1
console.log(gen.next().value); // 2
console.log(gen.next().value); // 3
console.log(gen.next().value); // 5
console.log(gen.next().value); // 8The example can be run with: `npm install . && node index.js`