UNPKG

@arrows/array

Version:
48 lines (47 loc) 1.6 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.zipWith_ = void 0; const curry_1 = require("@arrows/composition/curry"); const _zipAllWith_ = (zippingFn, otherArr, arr) => { const length = Math.max(arr.length, otherArr.length); const newArr = new Array(length); for (let i = 0; i < length; i++) { newArr[i] = zippingFn(otherArr[i], arr[i]); } return newArr; }; const zipAllWith_ = curry_1.default(_zipAllWith_); const _zipWith_ = (zippingFn, otherArr, arr) => { const length = Math.min(arr.length, otherArr.length); const newArr = new Array(length); for (let i = 0; i < length; i++) { newArr[i] = zippingFn(otherArr[i], arr[i]); } return newArr; }; const curriedZipWith_ = curry_1.default(_zipWith_); /** * Zips two arrays producing new values with a zipping function, * that takes elements with the same indexes. * Zips until the length of the shorter array is reached. * * @param zippingFn Zipping function * @param otherArr Array that you want to zip with initial array * @param arr Initial array * @returns New, zipped array * * @method all Zips until the length of the longer array is reached */ const zipWith_ = Object.assign(curriedZipWith_, { /** * Zips until the length of the longer array is reached. * * @param zippingFn Zipping function * @param otherArr Array that you want to zip with initial array * @param arr Initial array * @returns New, zipped array */ all: zipAllWith_, }); exports.zipWith_ = zipWith_; exports.default = zipWith_;