UNPKG

728 BJavaScriptView Raw
1/**
2 * @name arrayRange
3 * @summary Returns a range of numbers ith the size and the specified offset
4 * @description
5 * Returns a new array of numbers with the specific size. Optionally, when `startAt`, is provided, it generates the range to start at a specific value.
6 * @example
7 * <BR>
8 *
9 * ```javascript
10 * import { arrayRange } from '@polkadot/util';
11 *
12 * arrayRange(5); // [0, 1, 2, 3, 4]
13 * arrayRange(3, 5); // [5, 6, 7]
14 * ```
15 */
16export function arrayRange(size, startAt = 0) {
17 if (size <= 0) {
18 throw new Error('Expected non-zero, positive number as a range size');
19 }
20 const result = new Array(size);
21 for (let i = 0; i < size; i++) {
22 result[i] = i + startAt;
23 }
24 return result;
25}
\No newline at end of file