Lazy Range
Category: JavaScript
Usage
You want to use a lazy range if you have large ranges with many numbers inside it. By this, you reduce the memory overhead drastically.
Explanation
This range function uses a generator function. Generator functions are special because they can save their state and return (yield) multiple times. In this case, the generator always yields the next number, and after that, it increments this number and returns that incremented number the next time you call the generator.
In this case, the generator is called whenever the for..of loop executes the next time.
Performance
This function is fast because generators are fast enough. Thanks to the gnerator, you won’t need to care too much about memory consumption.