UNPKG

861 BJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.arrayRange = void 0;
4/**
5 * @name arrayRange
6 * @summary Returns a range of numbers ith the size and the specified offset
7 * @description
8 * 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.
9 * @example
10 * <BR>
11 *
12 * ```javascript
13 * import { arrayRange } from '@polkadot/util';
14 *
15 * arrayRange(5); // [0, 1, 2, 3, 4]
16 * arrayRange(3, 5); // [5, 6, 7]
17 * ```
18 */
19function arrayRange(size, startAt = 0) {
20 if (size <= 0) {
21 throw new Error('Expected non-zero, positive number as a range size');
22 }
23 const result = new Array(size);
24 for (let i = 0; i < size; i++) {
25 result[i] = i + startAt;
26 }
27 return result;
28}
29exports.arrayRange = arrayRange;