# RangeObject

class RangeObject(startOrObject, end, step=1, group)

Range objects are vanilla ES objects used to describe value range sets for use by compute.for(). The range must be increasing, i.e. start must be less than end. Calculations made to derive the set of numbers in a range are carried out with BigNumber, eg. arbitrary-precision, support. The numbers Infinity and -Infinity are not supported, and the API does not differentiate between +0 and -0.

An object which represents a range of values.

Arguments
• startOrObject (number|object()) – Beginning of range, or object literal with start and end properties.

• end (number()) – End of range

• step (number()) – Step size in range

• group (number|undefined()) – Groups in range

Examples:

<caption>With implicit step size = 1.</caption>
let rangeObject = new RangeObject(0.5,3);
rangeObject.toArray();
// [ 0.5, 1.5, 2.5 ]

<caption>With explicit step size.</caption>
let rangeObject = new RangeObject(1,9,3);
rangeObject.toArray();
// [ 1, 4, 7 ]

<caption>With grouping.</caption>
let rangeObject = new RangeObject(1,9,3,2);
rangeObject.toArray();
// [ [ 1, 4 ], [ 7 ] ]


## Examples

### With implicit step size = 1

const { RangeObject } = require('dcp/range-object');

const rangeObject = new RangeObject(0.5, 3);
rangeObject.toArray();
// [ 0.5, 1.5, 2.5 ]


### With explicit step size

const { RangeObject } = require('dcp/range-object');

const rangeObject = new RangeObject(1, 9, 3);
rangeObject.toArray();
// [ 1, 4, 7 ]


### With grouping

const { RangeObject } = require('dcp/range-object');

const rangeObject = new RangeObject(1, 9, 3, 2);
console.log(rangeObject.toArray());
// [ [ 1, 4 ], [ 7 ] ]


## Attributes

### length

RangeObject.length

Number of elements in range, or number of groups if grouped.

Examples:

<caption>Without grouping</caption>
let rangeObject = new RangeObject(1,10,3);
rangeObject.toArray();
// [ 1, 4, 7, 10 ]
rangeObject.length;
// 4

<caption>With grouping</caption>
let rangeObject = new RangeObject(1,9,3,2);
rangeObject.toArray();
// [ [ 1, 4 ], [ 7 ] ]
rangeObject.length;
// 2


## Methods

### nthValue

RangeObject.nthValue(n)

Return nth value in range

Arguments
• n (number()) –

Examples:

let rangeObject = new RangeObject(1,10,3,2);
rangeObject.toArray();
// [ [ 1, 4 ], [ 7, 10 ] ]
rangeObject.nthValue(1);
// [ 7, 10 ]


### toString

RangeObject.toString()

Create string representation of range: [object RangeObject start,end,step,group]

### toObject

RangeObject.toObject()

Create object literal for range with properties: start, end, step, and group.