7.6 KiB
| layout |
|---|
| default |
Range #
* [new Range(start, end, [step])](#new_Range_new) * _instance_ * [.size()](#Range+size) ⇒Array.<number>
* [.min()](#Range+min) ⇒ number | undefined
* [.max()](#Range+max) ⇒ number | undefined
* [.forEach(callback)](#Range+forEach)
* [.map(callback)](#Range+map) ⇒ Array
* [.toArray()](#Range+toArray) ⇒ Array
* [.valueOf()](#Range+valueOf) ⇒ Array
* [.format([options])](#Range+format) ⇒ string
* [.toString()](#Range+toString) ⇒ string
* [.toJSON()](#Range+toJSON) ⇒ Object
* _static_
* [.parse(str)](#Range.parse) ⇒ [Range](#Range) | null
* [.fromJSON(json)](#Range.fromJSON) ⇒ [Range](#Range)
new Range(start, end, [step]) #
Create a range. A range has a start, step, and end, and contains functions to iterate over the range.A range can be constructed as: var range = new Range(start, end); var range = new Range(start, end, step);
To get the result of the range: range.forEach(function (x) { console.log(x); }); range.map(function (x) { return math.sin(x); }); range.toArray();
Example usage: var c = new Range(2, 6); // 2:1:5 c.toArray(); // [2, 3, 4, 5] var d = new Range(2, -3, -1); // 2👎-2 d.toArray(); // [2, 1, 0, -1, -2]
| Param | Type | Description |
|---|---|---|
| start | number |
included lower bound |
| end | number |
excluded upper bound |
| [step] | number |
step size, default value is 1 |
range.size() ⇒ Array.<number> #
Retrieve the size of the range.
Returns an array containing one number, the number of elements in the range.
Kind: instance method of Range
Returns: Array.<number> - size
range.min() ⇒ number | undefined #
Calculate the minimum value in the range
Kind: instance method of Range
Returns: number | undefined - min
range.max() ⇒ number | undefined #
Calculate the maximum value in the range
Kind: instance method of Range
Returns: number | undefined - max
range.forEach(callback) #
Execute a callback function for each value in the range.Kind: instance method of Range
| Param | Type | Description |
|---|---|---|
| callback | function |
The callback method is invoked with three parameters: the value of the element, the index of the element, and the Range being traversed. |
range.map(callback) ⇒ Array #
Execute a callback function for each value in the Range, and return the
results as an array
Kind: instance method of Range
Returns: Array - array
| Param | Type | Description |
|---|---|---|
| callback | function |
The callback method is invoked with three parameters: the value of the element, the index of the element, and the Matrix being traversed. |
range.toArray() ⇒ Array #
Create an Array with a copy of the Ranges data
Kind: instance method of Range
Returns: Array - array
range.valueOf() ⇒ Array #
Get the primitive value of the Range, a one dimensional array
Kind: instance method of Range
Returns: Array - array
range.format([options]) ⇒ string #
Get a string representation of the range, with optional formatting options.
Output is formatted as 'start:step:end', for example '2:6' or '0:0.2:11'
Kind: instance method of Range
Returns: string - str
| Param | Type | Description |
|---|---|---|
| [options] | Object | number | function |
Formatting options. See lib/utils/number:format for a description of the available options. |
range.toString() ⇒ string #
Get a string representation of the range.
Kind: instance method of Range
range.toJSON() ⇒ Object #
Get a JSON representation of the range
Kind: instance method of Range
Returns: Object - Returns a JSON object structured as:
{"mathjs": "Range", "start": 2, "end": 4, "step": 1}
Range.parse(str) ⇒ [Range](#Range) | null #
Parse a string into a range,
The string contains the start, optional step, and end, separated by a colon.
If the string does not contain a valid range, null is returned.
For example str='0:2:11'.
Kind: static method of Range
Returns: Range | null - range
| Param | Type |
|---|---|
| str | string |
Range.fromJSON(json) ⇒ [Range](#Range) #
Instantiate a Range from a JSON object
Kind: static method of Range
| Param | Type | Description |
|---|---|---|
| json | Object |
A JSON object structured as: {"mathjs": "Range", "start": 2, "end": 4, "step": 1} |