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.
- package/index.js +12 -7
- 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 = (
|
|
453
|
-
const result = {
|
|
454
|
-
for (const
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
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,
|