Files
30-seconds-of-code/test/unzipWith/unzipWith.js
2018-02-04 17:38:39 +02:00

10 lines
231 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;