@@ -102,9 +102,9 @@ var arr = ndarray2array( y );
102102The function accepts the following arguments:
103103
104104- ** x** : input [ ndarray] [ @stdlib/ndarray/ctor ] .
105- - ** options** : function options.
105+ - ** options** : function options _ (optional) _ .
106106- ** predicate** : predicate function.
107- - ** thisArg** : predicate function execution context.
107+ - ** thisArg** : predicate function execution context _ (optional) _ .
108108
109109The function accepts the following options:
110110
@@ -146,6 +146,41 @@ var arr = ndarray2array( y );
146146// returns [ 8.0, 9.0, 10.0 ]
147147```
148148
149+ To set the ` predicate ` function execution context, provide a ` thisArg ` .
150+
151+ <!-- eslint-disable no-invalid-this, max-len -->
152+
153+ ``` javascript
154+ var Float64Array = require ( ' @stdlib/array-float64' );
155+ var ndarray = require ( ' @stdlib/ndarray-ctor' );
156+ var ndarray2array = require ( ' @stdlib/ndarray-to-array' );
157+
158+ function predicate ( z ) {
159+ this .count += 1 ;
160+ return z > 6.0 ;
161+ }
162+
163+ var buffer = new Float64Array ( [ 1.0 , 2.0 , 3.0 , 4.0 , 5.0 , 6.0 , 7.0 , 8.0 , 9.0 , 10.0 , 11.0 , 12.0 ] );
164+ var shape = [ 2 , 3 ];
165+ var strides = [ 6 , 1 ];
166+ var offset = 1 ;
167+
168+ var x = ndarray ( ' float64' , buffer, shape, strides, offset, ' row-major' );
169+ // returns <ndarray>
170+
171+ var ctx = {
172+ ' count' : 0
173+ };
174+ var y = filter ( x, predicate, ctx );
175+ // returns <ndarray>
176+
177+ var arr = ndarray2array ( y );
178+ // returns [ 8.0, 9.0, 10.0 ]
179+
180+ var count = ctx .count ;
181+ // returns 6
182+ ```
183+
149184The ` predicate ` function is provided the following arguments:
150185
151186- ** value** : current array element.
0 commit comments