Files
30-seconds-of-code/test/unzipWith/unzipWith.js
2018-08-02 13:49:33 +03:00

11 lines
272 B
JavaScript

const unzipWith = (arr, fn) =>
arr
.reduce(
(acc, val) => (val.forEach((v, i) => acc[i].push(v)), acc),
Array.from({
length: Math.max(...arr.map(x => x.length))
}).map(x => [])
)
.map(val => fn(...val));
module.exports = unzipWith;