blob: 336688ca706c8ac9d81f2b4ba8726ab7a311be39 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
'use strict';
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
module.exports = function array_sum(array) {
// eslint-disable-line camelcase
// discuss at: http://locutus.io/php/array_sum/
// original by: Kevin van Zonneveld (http://kvz.io)
// bugfixed by: Nate
// bugfixed by: Gilbert
// improved by: David Pilia (http://www.beteck.it/)
// improved by: Brett Zamir (http://brett-zamir.me)
// example 1: array_sum([4, 9, 182.6])
// returns 1: 195.6
// example 2: var $total = []
// example 2: var $index = 0.1
// example 2: for (var $y = 0; $y < 12; $y++){ $total[$y] = $y + $index }
// example 2: array_sum($total)
// returns 2: 67.2
var key;
var sum = 0;
// input sanitation
if ((typeof array === 'undefined' ? 'undefined' : _typeof(array)) !== 'object') {
return null;
}
for (key in array) {
if (!isNaN(parseFloat(array[key]))) {
sum += parseFloat(array[key]);
}
}
return sum;
};
//# sourceMappingURL=array_sum.js.map
|