1.0.0 • Published 4 years ago
@feizheng/next-sum v1.0.0
next-sum
Gets the sum of the values in collection.
installation
npm install -S @feizheng/next-sum
usage
import '@feizheng/next-sum';
const arr1 = [1, 2, 3, 4, 5];
const arr2 = [
{ key: '1', value: 111 },
{ key: '2', value: 222 },
{ key: '3', value: 333 },
{ key: '4', value: 444 }
];
const arr3 = [
{ key: 1, value: 111 },
{ key: 2, value: null },
{ key: 3, value: 2 },
{ key: 3, value: 'abc555' }
];
// simple
nx.sum(arr1); // 15
nx.sum(arr2, 'value'); // 1110
// with callback
nx.sum(arr3, function (_, item) {
var val = parseInt(item.value, 10);
return val ? val : 0;
});
// 113
license
Code released under the MIT license.
1.0.0
4 years ago