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
Applies `fn` to each element of `xs` from beginning to end. Function `fn` has two parameters: the item from the list and an “accumulator”; which starts with a value of `init`. `reduce` returns the final value of the accumulator.
705
705
706
706
```res example
707
-
Array.reduce([2, 3, 4], (a, b) => a + b, 1) == 10
707
+
Array.reduce([2, 3, 4], 1, (a, b) => a + b) == 10
708
708
709
-
Array.reduce(["a", "b", "c", "d"], (a, b) => a ++ b, "") == "abcd"
709
+
Array.reduce(["a", "b", "c", "d"], "", (a, b) => a ++ b) == "abcd"
710
710
```
711
711
*/
712
712
letreduce: (array<'a>, 'b, ('b, 'a) =>'b) =>'b
713
713
714
714
/**
715
-
`reduceWithIndex(xs, fn, init)`
715
+
`reduceWithIndex(x, init, fn)`
716
716
717
717
Applies `fn` to each element of `xs` from beginning to end. Function `fn` has three parameters: the item from the array and an “accumulator”, which starts with a value of `init` and the index of each element. `reduceWithIndex` returns the final value of the accumulator.
718
718
719
719
```res example
720
-
Array.reduceWithIndex([1, 2, 3, 4], (acc, x, i) => acc + x + i, 0) == 16
0 commit comments