Skip to content

Commit d2ca7e6

Browse files
Fixing the reduce documentation (#431)
* Fixing the reduce documentation The order of the parameters documentation was wrong, reduce callback will receive the accumulator first, item from the array and then the index of the item * Apply suggestions from code review * Update pages/docs/manual/latest/api/belt/array.mdx * Update pages/docs/manual/latest/api/belt/array.mdx Co-authored-by: Patrick Ecker <[email protected]>
1 parent 9e11bf6 commit d2ca7e6

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

pages/docs/manual/latest/api/belt/array.mdx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -701,12 +701,16 @@ let reduceU: (array<'b>, 'a, (. 'a, 'b) => 'a) => 'a
701701
let reduce: (array<'b>, 'a, ('a, 'b) => 'a) => 'a
702702
```
703703

704-
`reduce(xs, init, f)`
704+
`reduce(arr, init, f)`
705705

706-
Applies `f` to each element of `xs` from beginning to end. Function `f` 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.
706+
Applies `f` to each element of `arr`.
707+
708+
Function `f` has two parameters: an "accumulator" which starts with a value of `init` and the next value from the array.
709+
710+
It returns the final value of the accumulator.
707711

708712
```res example
709-
Belt.Array.reduce([2, 3, 4], 1, (a, b) => a + b) == 10
713+
Belt.Array.reduce([2, 3, 4], 1, (acc, value) => acc + value) == 10
710714
711715
Belt.Array.reduce(["a", "b", "c", "d"], "", (a, b) => a ++ b) == "abcd"
712716
```

0 commit comments

Comments
 (0)