Ensure _.sum and _.sumBy return 0 for empty arrays. [closes #1883]

This commit is contained in:
John-David Dalton
2016-01-26 01:29:18 -08:00
parent 25c7c8b153
commit 7a8ef7aeb7
2 changed files with 14 additions and 5 deletions

View File

@@ -841,7 +841,7 @@
result = result === undefined ? current : (result + current);
}
}
return result;
return length ? result : 0;
}
/**
@@ -13917,7 +13917,7 @@
function sum(array) {
return (array && array.length)
? baseSum(array, identity)
: undefined;
: 0;
}
/**
@@ -13945,7 +13945,7 @@
function sumBy(array, iteratee) {
return (array && array.length)
? baseSum(array, getIteratee(iteratee))
: undefined;
: 0;
}
/*------------------------------------------------------------------------*/