matrixrange.md (6167B)
1 <a name="Range"></a> 2 ## Range 3 * [new Range(start, end, [step])](#new_Range_new) 4 * _instance_ 5 * [.size()](#Range+size) ⇒ <code>Array.<number></code> 6 * [.min()](#Range+min) ⇒ <code>number</code> | <code>undefined</code> 7 * [.max()](#Range+max) ⇒ <code>number</code> | <code>undefined</code> 8 * [.forEach(callback)](#Range+forEach) 9 * [.map(callback)](#Range+map) ⇒ <code>Array</code> 10 * [.toArray()](#Range+toArray) ⇒ <code>Array</code> 11 * [.valueOf()](#Range+valueOf) ⇒ <code>Array</code> 12 * [.format([options])](#Range+format) ⇒ <code>string</code> 13 * [.toString()](#Range+toString) ⇒ <code>string</code> 14 * [.toJSON()](#Range+toJSON) ⇒ <code>Object</code> 15 * _static_ 16 * [.parse(str)](#Range.parse) ⇒ <code>[Range](#Range)</code> | <code>null</code> 17 * [.fromJSON(json)](#Range.fromJSON) ⇒ <code>[Range](#Range)</code> 18 19 <a name="new_Range_new"></a> 20 ### new Range(start, end, [step]) 21 Create a range. A range has a start, step, and end, and contains functions 22 to iterate over the range. 23 24 A range can be constructed as: 25 26 ```js 27 const range = new Range(start, end) 28 const range = new Range(start, end, step) 29 ``` 30 31 To get the result of the range: 32 33 ```js 34 range.forEach(function (x) { 35 console.log(x) 36 }) 37 range.map(function (x) { 38 return math.sin(x) 39 }) 40 range.toArray() 41 ``` 42 43 Example usage: 44 45 ```js 46 const c = new Range(2, 6) // 2:1:5 47 c.toArray() // [2, 3, 4, 5] 48 const d = new Range(2, -3, -1) // 2:-1:-2 49 d.toArray() // [2, 1, 0, -1, -2] 50 ``` 51 52 | Param | Type | Description | 53 | --- | --- | --- | 54 | start | <code>number</code> | included lower bound | 55 | end | <code>number</code> | excluded upper bound | 56 | [step] | <code>number</code> | step size, default value is 1 | 57 58 <a name="Range+size"></a> 59 ### range.size() ⇒ <code>Array.<number></code> 60 Retrieve the size of the range. 61 Returns an array containing one number, the number of elements in the range. 62 63 **Kind**: instance method of <code>[Range](#Range)</code> 64 **Returns**: <code>Array.<number></code> - size 65 <a name="Range+min"></a> 66 ### range.min() ⇒ <code>number</code> | <code>undefined</code> 67 Calculate the minimum value in the range 68 69 **Kind**: instance method of <code>[Range](#Range)</code> 70 **Returns**: <code>number</code> | <code>undefined</code> - min 71 <a name="Range+max"></a> 72 ### range.max() ⇒ <code>number</code> | <code>undefined</code> 73 Calculate the maximum value in the range 74 75 **Kind**: instance method of <code>[Range](#Range)</code> 76 **Returns**: <code>number</code> | <code>undefined</code> - max 77 <a name="Range+forEach"></a> 78 ### range.forEach(callback) 79 Execute a callback function for each value in the range. 80 81 **Kind**: instance method of <code>[Range](#Range)</code> 82 83 | Param | Type | Description | 84 | --- | --- | --- | 85 | 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. | 86 87 <a name="Range+map"></a> 88 ### range.map(callback) ⇒ <code>Array</code> 89 Execute a callback function for each value in the Range, and return the 90 results as an array 91 92 **Kind**: instance method of <code>[Range](#Range)</code> 93 **Returns**: <code>Array</code> - array 94 95 | Param | Type | Description | 96 | --- | --- | --- | 97 | 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. | 98 99 <a name="Range+toArray"></a> 100 ### range.toArray() ⇒ <code>Array</code> 101 Create an Array with a copy of the Ranges data 102 103 **Kind**: instance method of <code>[Range](#Range)</code> 104 **Returns**: <code>Array</code> - array 105 <a name="Range+valueOf"></a> 106 ### range.valueOf() ⇒ <code>Array</code> 107 Get the primitive value of the Range, a one dimensional array 108 109 **Kind**: instance method of <code>[Range](#Range)</code> 110 **Returns**: <code>Array</code> - array 111 <a name="Range+format"></a> 112 ### range.format([options]) ⇒ <code>string</code> 113 Get a string representation of the range, with optional formatting options. 114 Output is formatted as 'start:step:end', for example '2:6' or '0:0.2:11' 115 116 **Kind**: instance method of <code>[Range](#Range)</code> 117 **Returns**: <code>string</code> - str 118 119 | Param | Type | Description | 120 | --- | --- | --- | 121 | [options] | <code>Object</code> | <code>number</code> | <code>function</code> | Formatting options. See lib/utils/number:format for a description of the available options. | 122 123 <a name="Range+toString"></a> 124 ### range.toString() ⇒ <code>string</code> 125 Get a string representation of the range. 126 127 **Kind**: instance method of <code>[Range](#Range)</code> 128 <a name="Range+toJSON"></a> 129 ### range.toJSON() ⇒ <code>Object</code> 130 Get a JSON representation of the range 131 132 **Kind**: instance method of <code>[Range](#Range)</code> 133 **Returns**: <code>Object</code> - Returns a JSON object structured as: 134 `{"mathjs": "Range", "start": 2, "end": 4, "step": 1}` 135 <a name="Range.parse"></a> 136 ### Range.parse(str) ⇒ <code>[Range](#Range)</code> | <code>null</code> 137 Parse a string into a range, 138 The string contains the start, optional step, and end, separated by a colon. 139 If the string does not contain a valid range, null is returned. 140 For example str='0:2:11'. 141 142 **Kind**: static method of <code>[Range](#Range)</code> 143 **Returns**: <code>[Range](#Range)</code> | <code>null</code> - range 144 145 | Param | Type | 146 | --- | --- | 147 | str | <code>string</code> | 148 149 <a name="Range.fromJSON"></a> 150 ### Range.fromJSON(json) ⇒ <code>[Range](#Range)</code> 151 Instantiate a Range from a JSON object 152 153 **Kind**: static method of <code>[Range](#Range)</code> 154 155 | Param | Type | Description | 156 | --- | --- | --- | 157 | json | <code>Object</code> | A JSON object structured as: `{"mathjs": "Range", "start": 2, "end": 4, "step": 1}` | 158