- Returns single value.
- Doesn't mutate original array.
- Doesn't execute the function for empty array elements.
- Syntax:
array.reduce(function(previousValue, currentValue, currentIndex, arr), initialValue);
previousValue:
value resulting from the previous call to callBackFn. On first call, initialValue
if specified otherwise array[0]
.
currentValue:
value of the current element.On the first call, the value of array[0] if initialValue
specified otherwise array[1]
.
currentIndex:
currentValue index. On first call it is 0 if initialValue
specified otherwise 1.
Examples
Functional Composition:
In above, example input
is function returned by (...functions)
as we are calling multiply6(6)
.
Hence input is 6.
Reference: MDN official
Thank you. :)