Travis build: 1782 [cron]

This commit is contained in:
30secondsofcode
2018-03-06 20:32:31 +00:00
parent e7c5bcf6c6
commit 536373e77b
4 changed files with 48 additions and 13 deletions

View File

@ -1,11 +1,8 @@
const zipWith = (...arrays) => {
const length = arrays.length;
let fn = length > 1 ? arrays[length - 1] : undefined;
fn = typeof fn == 'function' ? (arrays.pop(), fn) : undefined;
const maxLength = Math.max(...arrays.map(x => x.length));
const result = Array.from({ length: maxLength }).map((_, i) => {
return Array.from({ length: arrays.length }, (_, k) => arrays[k][i]);
});
return fn ? result.map(arr => fn(...arr)) : result;
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;