Added empty array check
Added empty array check to the second ("right") solution.
This commit is contained in:
parent
72528a31fd
commit
c44ac8f7b9
1 changed files with 1 additions and 0 deletions
|
@ -31,6 +31,7 @@ alert(getSums([1,2,3,4,5])); // результат: *!*1,3,6,10*/!*
|
||||||
//+ run
|
//+ run
|
||||||
function getSums(arr) {
|
function getSums(arr) {
|
||||||
var result = [];
|
var result = [];
|
||||||
|
if (!arr.length) return result;
|
||||||
|
|
||||||
*!*var totalSum*/!* = arr.reduce(function(sum, item) {
|
*!*var totalSum*/!* = arr.reduce(function(sum, item) {
|
||||||
result.push(sum);
|
result.push(sum);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue