Skip to content

Instantly share code, notes, and snippets.

@miensol
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miensol/30aa3afe5396bdc6b8c1 to your computer and use it in GitHub Desktop.
Save miensol/30aa3afe5396bdc6b8c1 to your computer and use it in GitHub Desktop.
oracle generator es6
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