Returns a copy of data with specified length. If the input array is too long, it is truncated.
data
If the input array is too short, it will be expanded based on the expand strategy:
expand
undefined
import { Arrays } from 'https://unpkg.com/ixfx/dist/data.js';Arrays.ensureLength([1,2,3], 2); // [1,2]Arrays.ensureLength([1,2,3], 5, `undefined`); // [1,2,3,undefined,undefined]Arrays.ensureLength([1,2,3], 5, `repeat`); // [1,2,3,1,2]Arrays.ensureLength([1,2,3], 5, `first`); // [1,2,3,1,1]Arrays.ensureLength([1,2,3], 5, `last`); // [1,2,3,3,3] Copy
import { Arrays } from 'https://unpkg.com/ixfx/dist/data.js';Arrays.ensureLength([1,2,3], 2); // [1,2]Arrays.ensureLength([1,2,3], 5, `undefined`); // [1,2,3,undefined,undefined]Arrays.ensureLength([1,2,3], 5, `repeat`); // [1,2,3,1,2]Arrays.ensureLength([1,2,3], 5, `first`); // [1,2,3,1,1]Arrays.ensureLength([1,2,3], 5, `last`); // [1,2,3,3,3]
Type of array
Input array to expand
Desired length
Expand strategy
Returns a copy of
data
with specified length. If the input array is too long, it is truncated.If the input array is too short, it will be expanded based on the
expand
strategy:undefined
data
data