Skip to content

Commit 4490077

Browse files
committed
updated
1 parent d5aaaac commit 4490077

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

JavaScript Problem Solving/veryEasy.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,4 +232,17 @@ function addIndexes(arr) {
232232
return arr.map(function(currentVal, indexVal) {
233233
return currentVal + indexVal;
234234
});
235+
}
236+
237+
/*
238+
Get the Sum of All Array Elements
239+
Create a function that takes an array and returns the sum of all numbers in the array.
240+
Examples
241+
getSumOfItems([2, 7, 4]) ➞ 13
242+
*/
243+
function getSumOfItems(arr) {
244+
let reducer = function(acc, red) {
245+
return acc + red;
246+
}
247+
return arr.reduce(reducer);
235248
}

0 commit comments

Comments
 (0)