Returns a copy of an array with specified length - padded or truncated as needed.
If the input array is too short, it will be expanded based on the expand strategy:
expand
data
Truncate:
ensureLength([1,2,3], 2); // [1,2] Copy
ensureLength([1,2,3], 2); // [1,2]
Padded:
ensureLength([1,2,3], 5, `undefined`); // [1,2,3,undefined,undefined]ensureLength([1,2,3], 5, `repeat`); // [1,2,3,1,2]ensureLength([1,2,3], 5, `first`); // [1,2,3,1,1]ensureLength([1,2,3], 5, `last`); // [1,2,3,3,3] Copy
ensureLength([1,2,3], 5, `undefined`); // [1,2,3,undefined,undefined]ensureLength([1,2,3], 5, `repeat`); // [1,2,3,1,2]ensureLength([1,2,3], 5, `first`); // [1,2,3,1,1]ensureLength([1,2,3], 5, `last`); // [1,2,3,3,3]
Input array to expand
Desired length
Expand strategy
Type of array
Optional
Returns a copy of an array with specified length - padded or truncated as needed.
If the input array is too short, it will be expanded based on the
expand
strategy:data
data
Truncate:
Padded:
Param: data
Input array to expand
Param: length
Desired length
Param: expand
Expand strategy
Type Param: V
Type of array