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

9 lines
300 B
JavaScript

const zipWith = (...array) => {
const fn = typeof array[array.length - 1] === 'function' ? array.pop() : undefined;
return Array.from(
{ length: Math.max(...array.map(a => a.length)) },
(_, i) => (fn ? fn(...array.map(a => a[i])) : array.map(a => a[i]))
);
};
module.exports = zipWith;