mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-10 02:47:50 +00:00
Simplify _.sum.
This commit is contained in:
@@ -11191,8 +11191,13 @@
|
|||||||
* // => 12
|
* // => 12
|
||||||
*/
|
*/
|
||||||
function sum(array) {
|
function sum(array) {
|
||||||
if (!isArray(array) || array.length === 0) return NaN;
|
var length = array ? array.length : 0,
|
||||||
return arrayReduce(array, add, 0);
|
result = 0;
|
||||||
|
|
||||||
|
while (length--) {
|
||||||
|
result += array[length];
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*------------------------------------------------------------------------*/
|
/*------------------------------------------------------------------------*/
|
||||||
|
|||||||
Reference in New Issue
Block a user