You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 09_Day_Higher_order_functions/09_day_higher_order_functions.md
+12-5
Original file line number
Diff line number
Diff line change
@@ -236,10 +236,10 @@ ICELAND
236
236
237
237
### map
238
238
239
-
_map_: Iterate an array elements and modify the array elements. It takes a callback function with elements and index parameter and return a new array.
239
+
_map_: Iterate an array elements and modify the array elements. It takes a callback function with elements, index , array parameter and return a new array.
_reduce_: Reduce takes a callback function. The call back function takes accumulator and current value as a parameter and returns a single value:
368
+
_reduce_: Reduce takes a callback function. The call back function takes accumulator, current, and optional initial value as a parameter and returns a single value. It is a good practice to define an initial value for the accumulator value. If we do not specify this parameter, by default accumulator will get array `first value`. If our array is an _empty array_, then `Javascript` will throw an error.
369
+
370
+
```js
371
+
arr.reduce((acc, cur) => {
372
+
// some operations goes here before returning a value
0 commit comments