Range iterator that behaves like an Array
JavaScript
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
lib
test
.gitignore
.jshintrc
README.md
package.json

README.md

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