Last active
August 29, 2015 14:02
-
-
Save miensol/30aa3afe5396bdc6b8c1 to your computer and use it in GitHub Desktop.
oracle generator 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
var oracle = function *(){ | |
var question = yield "Hello"; | |
while(question != "Bye!"){ | |
var answer = Math.random(); | |
console.log(question, "oracle says: ", Math.random()); | |
question = yield answer; | |
} | |
console.log("Thank you!") | |
}; | |
var oracleGenerator = oracle(); | |
oracleGenerator.next("What is your name? - and why do you ignore my question?"); // {value: "Hello", done: false} | |
oracleGenerator.next("How old are you?"); // {value: 0.760754773626104, done: false} | |
oracleGenerator.next("Why?"); // {value: 0.36784305213950574, done: false} | |
oracleGenerator.next("Bye!"); // {value: undefined, done: true} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment