docs/reference/classes/matrixrange.md
<a name="Range"></a>
<a name="new_Range_new"></a>
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:
const range = new Range(start, end)
const 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:
const c = new Range(2, 6) // 2:1:5
c.toArray() // [2, 3, 4, 5]
const d = new Range(2, -3, -1) // 2:-1:-2
d.toArray() // [2, 1, 0, -1, -2]
| Param | Type | Description |
|---|---|---|
| start | <code>number</code> | included lower bound |
| end | <code>number</code> | excluded upper bound |
| [step] | <code>number</code> | step size, default value is 1 |
<a name="Range+size"></a>
Retrieve the size of the range. Returns an array containing one number, the number of elements in the range.
Kind: instance method of <code>Range</code>
Returns: <code>Array.<number></code> - size
<a name="Range+min"></a>
Calculate the minimum value in the range
Kind: instance method of <code>Range</code>
Returns: <code>number</code> | <code>undefined</code> - min
<a name="Range+max"></a>
Calculate the maximum value in the range
Kind: instance method of <code>Range</code>
Returns: <code>number</code> | <code>undefined</code> - max
<a name="Range+forEach"></a>
Execute a callback function for each value in the range.
Kind: instance method of <code>Range</code>
| Param | Type | Description |
|---|---|---|
| callback | <code>function</code> | The callback method is invoked with three parameters: the value of the element, the index of the element, and the Range being traversed. |
<a name="Range+map"></a>
Execute a callback function for each value in the Range, and return the results as an array
Kind: instance method of <code>Range</code>
Returns: <code>Array</code> - array
| Param | Type | Description |
|---|---|---|
| callback | <code>function</code> | The callback method is invoked with three parameters: the value of the element, the index of the element, and the Matrix being traversed. |
<a name="Range+toArray"></a>
Create an Array with a copy of the Ranges data
Kind: instance method of <code>Range</code>
Returns: <code>Array</code> - array
<a name="Range+valueOf"></a>
Get the primitive value of the Range, a one dimensional array
Kind: instance method of <code>Range</code>
Returns: <code>Array</code> - array
<a name="Range+format"></a>
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 <code>Range</code>
Returns: <code>string</code> - str
| Param | Type | Description |
|---|---|---|
| [options] | <code>Object</code> | <code>number</code> | <code>function</code> | Formatting options. See lib/utils/number:format for a description of the available options. |
<a name="Range+toString"></a>
Get a string representation of the range.
Kind: instance method of <code>Range</code>
<a name="Range+toJSON"></a>
Get a JSON representation of the range
Kind: instance method of <code>Range</code>
Returns: <code>Object</code> - Returns a JSON object structured as:
{"mathjs": "Range", "start": 2, "end": 4, "step": 1}
<a name="Range.parse"></a>
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 <code>Range</code>
Returns: <code>Range</code> | <code>null</code> - range
| Param | Type |
|---|---|
| str | <code>string</code> |
<a name="Range.fromJSON"></a>
Instantiate a Range from a JSON object
Kind: static method of <code>Range</code>
| Param | Type | Description |
|---|---|---|
| json | <code>Object</code> | A JSON object structured as: {"mathjs": "Range", "start": 2, "end": 4, "step": 1} |