Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

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
Comment

What is a generator function?

function xrange($min, $max) {
    for ($i = $min; $i <= $max; $i++) {
        yield $i;
    }
}

//[…]

foreach (xrange(1, 10) as $key => $value) {
    echo "$key => $value" . PHP_EOL;
}
Comment

generator function

function* generator() {
  yield 1;
  yield 2;
  yield 3;
}

const gen = generator(); // "Generator { }"

console.log(gen.next().value); // 1
console.log(gen.next().value); // 2
console.log(gen.next().value); // 3
Comment

PREVIOUS NEXT
Code Example
Javascript :: react-intersection-observer 
Javascript :: get date in format 
Javascript :: build json object 
Javascript :: asynchronous in javascript 
Javascript :: Printer Print using HTML 
Javascript :: js modulo not working 
Javascript :: moment get difference between business dates 
Javascript :: html select multiple selected values 
Javascript :: canvas rounded corners 
Javascript :: automated counter with react hooks 
Javascript :: document middleware in express 
Javascript :: js not not 
Javascript :: check whether array ascending 
Javascript :: remove the last character from a string in JavaScript, 
Javascript :: javascript online compiler 
Javascript :: display month friday 13th javascript year 
Javascript :: rc-notification react 
Javascript :: shopify api for add to cart 
Javascript :: get search value from reacr route3 
Javascript :: paginacion javascript 
Javascript :: js after settimeout 
Javascript :: set map to local storage javascript 
Javascript :: pop javascript 
Javascript :: adding cors parameters to extjs ajax 
Javascript :: nodejs remove element from array 
Javascript :: get search value from reacr route1 
Javascript :: javascript merging arrays 
Javascript :: how add class to ckeditor image 
Javascript :: javascript sort multi-dimensional array 
Javascript :: js insert in array 
ADD CONTENT
Topic
Content
Source link
Name
8+9 =