There's no good reason to limit ourselves to two, and no particularly good reason to post-filter.
const mergeArrays = (...arrays) => { const result = []; const length = Math.max(...arrays.map(array => array.length)); for (let nth = 0; nth < length; nth++) { for (const array of arrays) { const item = array[nth]; if (item !== undefined) { result.push(item); } } } return result; } console.log(mergeArrays([9, 10, 11], ["a"])); // [9, "a", 10, 11] ✅ console.log(mergeArrays([1], ["a", "b"])); // [1, "a", "b"] ✅
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
There's no good reason to limit ourselves to two, and no particularly good reason to post-filter.