Answers for "Generator function"

4

javascript generator function

function* idMaker() {
  var index = 0;
  while (true)
    yield index++;
}

var gen = idMaker();

console.log(gen.next().value); // 0
console.log(gen.next().value); // 1
console.log(gen.next().value); // 2
console.log(gen.next().value); // 3
// ...
Posted by: Guest on June-06-2020
0

Generator Function

# A generator function that yields 1 for first time,
# 2 second time and 3 third time
def simpleGeneratorFun():
    yield 1            
    yield 2            
    yield 3            
   
# Driver code to check above generator function
for value in simpleGeneratorFun(): 
    print(value)
Posted by: Guest on August-10-2021
0

Generator function

function* indexGenerator(){
  var index = 0;
  while(true) {
    yield index++;
  }
}
const g = indexGenerator();
console.log(g.next().value); // => 0
console.log(g.next().value); // => 1
Posted by: Guest on September-17-2021
0

function generator js

function* name([param[, param[, ... param]]]) {
   statements
}
Posted by: Guest on July-27-2020
-1

JavaScript — Generators

function* makeRangeIterator(start = 0, end = 100, step = 1) {
    let iterationCount = 0;
    for (let i = start; i < end; i += step) {
        iterationCount++;
        yield i;
    }
    return iterationCount;
}
Posted by: Guest on November-05-2020

Code answers related to "Generator function"

Code answers related to "Javascript"

Browse Popular Code Answers by Language