Skip to content

Commit c445703

Browse files
committed
Auto-generated commit
1 parent ab70849 commit c445703

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
<details>
2424

25+
- [`855b8c2`](https://github.com/stdlib-js/stdlib/commit/855b8c255abba003e9505aa3a80105a2e2b6b3a7) - **docs:** add example _(by Athan Reines)_
2526
- [`1cc3e09`](https://github.com/stdlib-js/stdlib/commit/1cc3e095080947f8fdd61ea2217f9b3031b9f93b) - **docs:** fix annotation _(by Athan Reines)_
2627
- [`7efc6f3`](https://github.com/stdlib-js/stdlib/commit/7efc6f3c8f899974f7d11cb9e06f65f90d5caaa9) - **bench:** fix symbol name _(by Athan Reines)_
2728
- [`354a147`](https://github.com/stdlib-js/stdlib/commit/354a1472bd69ab26c020aa7ba1df043c88e985b2) - **docs:** add note _(by Athan Reines)_

README.md

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,9 @@ var arr = ndarray2array( y );
102102
The 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

109109
The 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+
149184
The `predicate` function is provided the following arguments:
150185

151186
- **value**: current array element.

0 commit comments

Comments
 (0)