Class

RangeObject

RangeObject(startOrObject, end, stepopt, groupopt)

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.

Constructor

# new RangeObject(startOrObject, end, stepopt, groupopt)

An object which represents a range of values.

Parameters:
Name Type Attributes Default Description
startOrObject number | object

Beginning of range, or object literal with start and end properties.

end number

End of range

step number <optional>
1

Step size in range

group number | undefined <optional>

Groups in range

Examples

With implicit step size = 1.

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

With explicit step size.

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

With grouping.

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

Extends

Members

# hasRemainder

Boolean indicating whether all groups are filled. Only defined for RangeObjects that group results.

Examples

With remainder

let rangeObject = new RangeObject(1,9,3,2);
rangeObject.toArray();
// [ [ 1, 4 ], [ 7 ] ]
rangeObject.hasRemainder;
// true

Without remainder

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

# length

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

Examples

Without grouping

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

With grouping

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

# max

Return max value in range

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

# stepCount

Number of steps in range (sort of like number of elements, except grouping is no longer relevant).

Examples

Without grouping

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

With grouping

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

Methods

# filter(…args)

Converts range to an Array and then calls filter(...args) on it.

Parameters:
Name Type Attributes Description
args any <repeatable>

Same args as you would pass to Array#filter

Overrides:

# nthValue(n)

Return nth value in range

Parameters:
Name Type Description
n number
Example
let rangeObject = new RangeObject(1,10,3,2);
rangeObject.toArray();
// [ [ 1, 4 ], [ 7, 10 ] ]
rangeObject.nthValue(1);
// [ 7, 10 ]

# slice(startopt, endopt)

Generate array from range starting at value start and ending at value end via nthValue.

Parameters:
Name Type Attributes Default Description
start number <optional>
0

index to start slice

end number <optional>

index to end slice, return rest of array if not provided.

Overrides:

# toObject()

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

# toString()

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