UNPKG

everyutil

Version:

A comprehensive library of lightweight, reusable utility functions for JavaScript and TypeScript, designed to streamline common programming tasks such as string manipulation, array processing, date handling, and more.

23 lines (22 loc) 592 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.interleave = void 0; /** * Mixes arrays in a round-robin pattern. * @author @dailker * @template T * @param {...T[][]} arrays * @returns {T[]} */ function interleave(...arrays) { const maxLen = Math.max(...arrays.map(arr => arr.length)); const result = []; for (let i = 0; i < maxLen; i++) { for (const arr of arrays) { if (i < arr.length) result.push(arr[i]); } } return result; } exports.interleave = interleave;