range.md (1867B)
1 <!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. --> 2 3 # Function range 4 5 Create an array from a range. 6 By default, the range end is excluded. This can be customized by providing 7 an extra parameter `includeEnd`. 8 9 10 ## Syntax 11 12 ```js 13 math.range(str [, includeEnd]) // Create a range from a string, 14 // where the string contains the 15 // start, optional step, and end, 16 // separated by a colon. 17 math.range(start, end [, includeEnd]) // Create a range with start and 18 // end and a step size of 1. 19 math.range(start, end, step [, includeEnd]) // Create a range with start, step, 20 // and end. 21 ``` 22 23 ### Where 24 25 - `str: string` 26 A string 'start:end' or 'start:step:end' 27 - `start: {number | BigNumber}` 28 Start of the range 29 - `end: number | BigNumber` 30 End of the range, excluded by default, included when parameter includeEnd=true 31 - `step: number | BigNumber` 32 Step size. Default value is 1. 33 - `includeEnd: boolean` 34 Option to specify whether to include the end or not. False by default. 35 36 ### Parameters 37 38 Parameter | Type | Description 39 --------- | ---- | ----------- 40 `args` | * | Parameters describing the ranges `start`, `end`, and optional `step`. 41 42 ### Returns 43 44 Type | Description 45 ---- | ----------- 46 Array | Matrix | range 47 48 49 ### Throws 50 51 Type | Description 52 ---- | ----------- 53 54 55 ## Examples 56 57 ```js 58 math.range(2, 6) // [2, 3, 4, 5] 59 math.range(2, -3, -1) // [2, 1, 0, -1, -2] 60 math.range('2:1:6') // [2, 3, 4, 5] 61 math.range(2, 6, true) // [2, 3, 4, 5, 6] 62 ``` 63 64 65 ## See also 66 67 [ones](ones.md), 68 [zeros](zeros.md), 69 [size](size.md), 70 [subset](subset.md)