@dobesv/parquets
Version:
TypeScript implementation of the Parquet file format, based on parquet.js
43 lines • 1.36 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
/**
* Merge the given arrays into one. The resulting array will have the
* same type as the first one.
*
* If only the first array is non-empty (or there is just one array)
* it will be returned unmodified.
*
* @param arrays Arrays to merge
*/
function concatValueArrays(arrays) {
if (arrays.length === 0) {
return [];
}
const head = arrays[0];
if (arrays.length === 1) {
return head;
}
// If we're dealing with normal arrays, just use Array.prototype.concat
if (Array.isArray(head)) {
return Array.prototype.concat(...arrays);
}
// Now we must be dealing with primitive arrays
// Calculate the total size of all the arrays combined
const totalSize = arrays.reduce((a, b) => a + b.length, 0);
// Are all the arrays after the first actually empty? If so just return the first one
if (totalSize === head.length) {
return head;
}
const arrayType = head.constructor;
const result = new arrayType(totalSize);
let offset = 0;
for (const array of arrays) {
if (array.length) {
result.set(array, offset);
offset += array.length;
}
}
return result;
}
exports.default = concatValueArrays;
//# sourceMappingURL=concatValueArrays.js.map