JavaScript / October 2, 2010

JS Generator – Fibonacci Example

[js] function fibonacci() { var i1 = 0, i2 = 1; while (true) { yield i1; var t = i1; i1 = i2; i2 += t; } } var g = fibonacci(); for (var i = 0; i < 10; i++) { document.write(g.next() + "\n"); } [/js] The function fibonacci contains the keyword “yield” making

Read More