JSFiddle - React, Tailwind, and code Playground

by Bala_chandran

JavaScript

/*Calling a generator function does not execute its body immediately; an iterator object for the function is returned instead. When the iterator's next() method is called, the generator function's body is executed until the first yield expression, which specifies the value to be returned from the iterator or, with yield*, delegates to another generator function.*/

/*function* welcome() {
  console.log('call me next');
}

let x = welcome();

console.log(x);
var next = x.next();
console.log(next);

console.log(x.next());*/


/*function* welcome() {
  console.log('call 1');
  yield "How";
  console.log('call 2');
  yield "are";
  console.log('call 3');
  yield "you";
  console.log('call 4');
}

//var gen = welcome();
//var one = gen.next();
//console.log(one);
//var two = gen.next();
//console.log(two);

//or
var gen = welcome();
for(let word of gen){
  console.log(word);
}*/


// ex3

/*function* welcome() {
 let catchYield= yield "How";
  yield catchYield+"are";
  yield "you";
}

let gen=welcome();
gen.next();
console.log(gen.next("catch ").value);*/

// ex4 generate infinite graph

/*function* graph() {
  let x = 1,
    y = 2;

  while (true) {
    yield {
      x,
      y
    };
    x += 3;
    y += 2;
  }
}
var g=graph();
console.log(g.next().value)*/

/*
//With a generator
function* makeSimpleGenerator(array){
    var nextIndex = 0;
    
    while(nextIndex < array.length){
        yield array[nextIndex++];
    }
}

var gen = makeSimpleGenerator(['yo', 'ya']);
debugger;
console.log(gen.next().value); // 'yo'
console.log(gen.next().value); // 'ya'
console.log(gen.next().done);  // true */