cafe-utility 2.2.0 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.js +12 -7
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -449,18 +449,22 @@ const mergeDeep = (target, source) => {
449
449
  }
450
450
  }
451
451
 
452
- const zip = (first, second, reducer) => {
453
- const result = { ...first }
454
- for (const entry of Object.entries(second)) {
455
- if (result[entry[0]]) {
456
- result[entry[0]] = reducer(result[entry[0]], entry[1])
457
- } else {
458
- result[entry[0]] = entry[1]
452
+ const zip = (objects, reducer) => {
453
+ const result = {}
454
+ for (const object of objects) {
455
+ for (const key of Object.keys(object)) {
456
+ if (result[key]) {
457
+ result[key] = reducer(result[key], object[key])
458
+ } else {
459
+ result[key] = object[key]
460
+ }
459
461
  }
460
462
  }
461
463
  return result
462
464
  }
463
465
 
466
+ const zipSum = objects => zip(objects, (x, y) => x + y)
467
+
464
468
  /**
465
469
  * @param {*} value
466
470
  * @returns {number}
@@ -1510,6 +1514,7 @@ module.exports = {
1510
1514
  runOn,
1511
1515
  ifPresent,
1512
1516
  zip,
1517
+ zipSum,
1513
1518
  removeEmptyArrays,
1514
1519
  removeEmptyValues,
1515
1520
  flatten,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cafe-utility",
3
- "version": "2.2.0",
3
+ "version": "3.0.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "exports": {