UNPKG

@augment-vir/common

Version:

A collection of augments, helpers types, functions, and classes for any JavaScript environment.

26 lines (25 loc) 677 B
/** * Repeats an array. Constructs a new array with the entries from the original repeated the given * number of times. * * @category Array * @category Package : @augment-vir/common * @example * * ```ts * import {repeatArray} from '@augment-vir/common'; * * const result = repeatArray(3, [ * 'a', * 'b', * 'c', * ]); * // result is `['a', 'b', 'c', 'a', 'b', 'c', 'a', 'b', 'c']` * ``` * * @returns A new array (does not mutate). * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common) */ export function repeatArray(repeatCount, array) { return Array.from({ length: repeatCount }, () => [...array]).flat(); }