Comparing version 0.23.1 to 0.24.0
@@ -399,4 +399,39 @@ 'use strict'; | ||
/** | ||
* Zip applies a specified function to the corresponding elements of two sequences, | ||
* producing a sequence of the results. | ||
* | ||
* @param {Array} array1 input array | ||
* @param {Array} array2 input array | ||
* @param {Function} predicate optional to be applied to corresponding values | ||
* @returns {Array} input array filled value pairs after the function has been applied | ||
* | ||
* @example | ||
* const result = zip([5, 12, 8, 130, 44], ["ham", "cheese", "bread"]); | ||
* console.log(result) | ||
* > [ [ 'ham', 5 ], [ 'cheese', 12 ], [ 'bread', 8 ] ] | ||
* @example | ||
* const result = zip([5, 12, 8], ["ham", "cheese", "bread"], (x, y) => x + " " + y); | ||
* console.log(result) | ||
* > [ 'ham 5', 'cheese 12', 'bread 8' ] | ||
*/ | ||
function zip (array1, array2, predicate = (a, b) => [a, b]) { | ||
if (predicate && typeof predicate !== 'function') { | ||
throw TypeError('predicate must be a function'); | ||
} | ||
if (array1.length <= array2.length) { | ||
return array1.reduce((res, cur, i) => { | ||
res[i] = predicate(cur, array2[i]); | ||
return res; | ||
}, []); | ||
} else { | ||
return array2.reduce((res, cur, i) => { | ||
res[i] = predicate(array1[i], cur); | ||
return res; | ||
}, []); | ||
} | ||
} | ||
var index = /*#__PURE__*/Object.freeze({ | ||
@@ -419,3 +454,4 @@ __proto__: null, | ||
reverse: reverse, | ||
tap: tap | ||
tap: tap, | ||
zip: zip | ||
}); | ||
@@ -422,0 +458,0 @@ |
@@ -395,4 +395,39 @@ /** | ||
/** | ||
* Zip applies a specified function to the corresponding elements of two sequences, | ||
* producing a sequence of the results. | ||
* | ||
* @param {Array} array1 input array | ||
* @param {Array} array2 input array | ||
* @param {Function} predicate optional to be applied to corresponding values | ||
* @returns {Array} input array filled value pairs after the function has been applied | ||
* | ||
* @example | ||
* const result = zip([5, 12, 8, 130, 44], ["ham", "cheese", "bread"]); | ||
* console.log(result) | ||
* > [ [ 'ham', 5 ], [ 'cheese', 12 ], [ 'bread', 8 ] ] | ||
* @example | ||
* const result = zip([5, 12, 8], ["ham", "cheese", "bread"], (x, y) => x + " " + y); | ||
* console.log(result) | ||
* > [ 'ham 5', 'cheese 12', 'bread 8' ] | ||
*/ | ||
function zip (array1, array2, predicate = (a, b) => [a, b]) { | ||
if (predicate && typeof predicate !== 'function') { | ||
throw TypeError('predicate must be a function'); | ||
} | ||
if (array1.length <= array2.length) { | ||
return array1.reduce((res, cur, i) => { | ||
res[i] = predicate(cur, array2[i]); | ||
return res; | ||
}, []); | ||
} else { | ||
return array2.reduce((res, cur, i) => { | ||
res[i] = predicate(array1[i], cur); | ||
return res; | ||
}, []); | ||
} | ||
} | ||
var index = /*#__PURE__*/Object.freeze({ | ||
@@ -415,3 +450,4 @@ __proto__: null, | ||
reverse: reverse, | ||
tap: tap | ||
tap: tap, | ||
zip: zip | ||
}); | ||
@@ -418,0 +454,0 @@ |
{ | ||
"name": "absurdum", | ||
"version": "0.23.1", | ||
"version": "0.24.0", | ||
"description": "Reductio Ad Absurdum - The Ridiculous Application of Reduce", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -65,2 +65,3 @@ [![GitHub release](https://img.shields.io/github/release/vanillaes/absurdum.svg)](https://github.com/vanillaes/absurdum/releases) | ||
- [tap][arrays.tap] | ||
- [zip][arrays.zip] | ||
@@ -83,2 +84,3 @@ [arrays.chunk]: ./docs/arrays/chunk.md | ||
[arrays.tap]: ./docs/arrays/tap.md | ||
[arrays.zip]: ./docs/arrays/zip.md | ||
@@ -85,0 +87,0 @@ ### Objects |
@@ -16,1 +16,2 @@ export { chunk } from "./chunk.js"; | ||
export { tap } from "./tap.js"; | ||
export { zip } from "./zip.js"; |
@@ -17,1 +17,2 @@ export { chunk } from './chunk.js'; | ||
export { tap } from './tap.js'; | ||
export { zip } from './zip.js'; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
82744
74
2171
108