UNPKG

1.81 kBMarkdownView Raw
1<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
2
3# Function range
4
5Create an array from a range.
6By default, the range end is excluded. This can be customized by providing
7an extra parameter `includeEnd`.
8
9
10## Syntax
11
12```js
13math.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.
17math.range(start, end [, includeEnd]) // Create a range with start and
18 // end and a step size of 1.
19math.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
38Parameter | Type | Description
39--------- | ---- | -----------
40`args` | * | Parameters describing the ranges `start`, `end`, and optional `step`.
41
42### Returns
43
44Type | Description
45---- | -----------
46Array &#124; Matrix | range
47
48
49## Examples
50
51```js
52math.range(2, 6) // [2, 3, 4, 5]
53math.range(2, -3, -1) // [2, 1, 0, -1, -2]
54math.range('2:1:6') // [2, 3, 4, 5]
55math.range(2, 6, true) // [2, 3, 4, 5, 6]
56```
57
58
59## See also
60
61[ones](ones.md),
62[zeros](zeros.md),
63[size](size.md),
64[subset](subset.md)