Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

56 lines (42 sloc) 1.848 kB

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
Jump to Line
Something went wrong with that request. Please try again.