Loading files
This file is pinned to the selected release. Download the original to open it in your design tool.
1c7200981This file is pinned to the selected release. Download the original to open it in your design tool.
/**
* Build an array of the given target length from an existing array and a padding value.
*
* If the array is already larger than the target length, it will not be shortened.
*
* @param {Array} anArray - the source array to copy into the result.
* @param {*} padding - the value to add to the new array to reach the desired length.
* @param {number} targetLength - The desired length of the returned array.
* @returns {Array} an array with at least 'target length" elements
*
* @alias module:array-utils.padToLength
* @function
*
* @example
* const srcArray = [2, 3, 4]
* const paddedArray = padToLength(srcArray, 0, 5) // returns [2, 3, 4, 0, 0]
*/
export const padToLength = (anArray, padding, targetLength) => {
anArray = anArray.slice()
while (anArray.length < targetLength) {
anArray.push(padding)
}
return anArray
}