File tree Expand file tree Collapse file tree 2 files changed +27
-9
lines changed Expand file tree Collapse file tree 2 files changed +27
-9
lines changed Original file line number Diff line number Diff line change 1
1
/**
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>.
6
15
*/
7
-
8
16
export function _reduce ( accumulator , iterable , initializer ) {
9
17
10
18
for ( let item of iterable ) {
Original file line number Diff line number Diff line change @@ -2,10 +2,20 @@ import { _reduce } from './_reduce' ;
2
2
import { iter } from '../base/iter' ;
3
3
4
4
/**
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>.
9
19
*/
10
20
11
21
export function reduce ( accumulator , iterable , initializer = undefined ) {
You can’t perform that action at this time.
0 commit comments