source: node_modules/ramda/es/zipWith.js@ d24f17c

main
Last change on this file since d24f17c was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Initial commit

  • Property mode set to 100644
File size: 1.2 KB
Line 
1import _curry3 from "./internal/_curry3.js";
2/**
3 * Creates a new list out of the two supplied by applying the function to each
4 * equally-positioned pair in the lists. The returned list is truncated to the
5 * length of the shorter of the two input lists.
6 *
7 * @function
8 * @memberOf R
9 * @since v0.1.0
10 * @category List
11 * @sig ((a, b) -> c) -> [a] -> [b] -> [c]
12 * @param {Function} fn The function used to combine the two elements into one value.
13 * @param {Array} list1 The first array to consider.
14 * @param {Array} list2 The second array to consider.
15 * @return {Array} The list made by combining same-indexed elements of `list1` and `list2`
16 * using `fn`.
17 * @example
18 *
19 * const f = (x, y) => {
20 * // ...
21 * };
22 * R.zipWith(f, [1, 2, 3], ['a', 'b', 'c']);
23 * //=> [f(1, 'a'), f(2, 'b'), f(3, 'c')]
24 * @symb R.zipWith(fn, [a, b, c], [d, e, f]) = [fn(a, d), fn(b, e), fn(c, f)]
25 */
26
27var zipWith =
28/*#__PURE__*/
29_curry3(function zipWith(fn, a, b) {
30 var rv = [];
31 var idx = 0;
32 var len = Math.min(a.length, b.length);
33
34 while (idx < len) {
35 rv[idx] = fn(a[idx], b[idx]);
36 idx += 1;
37 }
38
39 return rv;
40});
41
42export default zipWith;
Note: See TracBrowser for help on using the repository browser.