Created
September 26, 2016 13:07
-
-
Save arvitaly/0d51f2c5fc843e5ec0ac58372ca77797 to your computer and use it in GitHub Desktop.
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
var Fib = { | |
[Symbol.iterator]() { | |
var n1 = 1, n2 = 1; | |
return { | |
// make the iterator an iterable | |
[Symbol.iterator]() { return this; }, | |
next() { | |
var current = n2; | |
n2 = n1; | |
n1 = n1 + current; | |
return { value: current, done: false }; | |
}, | |
return(v) { | |
console.log( | |
"Fibonacci sequence abandoned." | |
); | |
return { value: v, done: true }; | |
} | |
}; | |
} | |
}; | |
for (var v of Fib) { | |
console.log(v); | |
if (v > 50) break; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment