range-iterator

Range iterator that behaves like an Array

npm install range-iterator
4 downloads in the last week
16 downloads in the last month

Range iterator that behaves like an Array

... but without having to hog up all the memory.

Install

npm install range-iterator

Usage

var Range = require('range-iterator').Range
  , iterator = new Range(12, 20, 3);
// or simply range(12, 20, 3) if `new` isn't your thing

iterator.forEach(function(i){
  console.log(i);
});

// outputs:
// 12
// 15
// 18

Constructor

The constructor takes the same parameters as Python's xrange function.

  • new Range(start, end, step)
  • new Range(start, end)new Range(start, end, 1)
  • new Range(end)new Range(0, end, 1)

Methods

Comes with all iteration methods that Array instances have.

As well as:

  • #get(n): obtain the value at step n
  • #toArray(): obtain the array of the Range instance

Properties

  • #length
  • #start
  • #step
npm loves you