Skip to content

Commit 8c53661

Browse files
fix documentation of reduce
1 parent d4888e4 commit 8c53661

File tree

2 files changed

+27
-9
lines changed

2 files changed

+27
-9
lines changed

src/reduce/_reduce.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
/**
2-
* Applies the accumulator function iteratively on the
3-
* last return value of the accumulator and the next
4-
* value in the iterable. The initial value is the initializer
5-
* parameter.
2+
* Applies the accumulator function iteratively on the last return value of the
3+
* accumulator and the next value in the input iterable. The initial value is
4+
* the initializer parameter.
5+
*
6+
* @example
7+
* _reduce( ( x , y ) => x + y , range( 10 ) , 0 ) ; // returns 45
8+
*
9+
* @example
10+
* _reduce( ( x , y ) => x + y , range( 10 ) , 100 ) ; // returns 145
11+
*
12+
* @param {Iterable} iterable - The input iterable.
13+
* @param {Object} initializer - The initial value of the reduction.
14+
* @returns {Object} - The reduction of the elements of <code>iterable</code>.
615
*/
7-
816
export function _reduce ( accumulator , iterable , initializer ) {
917

1018
for ( let item of iterable ) {

src/reduce/reduce.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,20 @@ import { _reduce } from './_reduce' ;
22
import { iter } from '../base/iter' ;
33

44
/**
5-
* Applies the accumulator function iteratively on the
6-
* last return value of the accumulator and the next
7-
* value in the iterable. The initial value is the initializer
8-
* parameter.
5+
* Applies the accumulator function iteratively on the last return value of the
6+
* accumulator and the next value in the input iterable. The initial value is
7+
* the initializer parameter. If no initial value is given, the first element
8+
* of the input iterable is used.
9+
*
10+
* @example
11+
* _reduce( ( x , y ) => x + y , range( 10 ) , 0 ) ; // returns 45
12+
*
13+
* @example
14+
* _reduce( ( x , y ) => x + y , range( 10 ) , 100 ) ; // returns 145
15+
*
16+
* @param {Iterable} iterable - The input iterable.
17+
* @param {Object} initializer - The initial value of the reduction.
18+
* @returns {Object} - The reduction of the elements of <code>iterable</code>.
919
*/
1020

1121
export function reduce ( accumulator , iterable , initializer = undefined ) {

0 commit comments

Comments
 (0)