Simplify _.sum.

This commit is contained in:
jdalton
2015-02-25 23:01:32 -08:00
parent 74786e8a25
commit 42d23dbc70

View File

@@ -11191,8 +11191,13 @@
* // => 12
*/
function sum(array) {
if (!isArray(array) || array.length === 0) return NaN;
return arrayReduce(array, add, 0);
var length = array ? array.length : 0,
result = 0;
while (length--) {
result += array[length];
}
return result;
}
/*------------------------------------------------------------------------*/