1.0.0 • Published 8 years ago
py-range v1.0.0
py-range
Lightweight implementation of Python's range( a, b, [step] ).
Install
$ npm install py-rangehttps://www.npmjs.com/package/py-range
Usage
const range = require( "py-range" );
range( 5 );
//=> [ 0, 1, 2, 3, 4 ]
range( 5, 12 );
//=> [ 5, 6, 7, 8, 9, 10, 11 ]
range( 5, 12, 2 );
//=> [ 5, 7, 9, 11 ]
range( 12, 5, -2 );
//=> [ 12, 10, 8, 6 ]API
range( a, b, step )
Returns array with values from a to b in steps and requires a < b.
a
Type: number
Specifies start of range. Returned array will start with a.
range( 1, 3 );
//=> [ 1, 2 ]Can be omited if zero:
range( 5 );
// Instead of
range( 0, 5 );Omiting a can't be used with step.
b
Type: number
Specifies end of range. Return array will end with b - 1.
range( 1, 3 );
//=> [ 1, 2 ]step
Optional
Type: number
Default: 1
Specifies step of range.
range( 5, 12, 2 );
//=> [ 5, 7, 9, 11 ]Can be negative, which requires a > b.
range( 12, 5, -2 );
//=> [ 12, 10, 8, 6 ]Test
$ npm run testLicense
MIT © Jonathan Neidel
1.0.0
8 years ago