mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-05 09:27:49 +00:00
Ensure _.sum and _.sumBy return 0 for empty arrays. [closes #1883]
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
|
||||
Reference in New Issue
Block a user