@@ -20,7 +20,7 @@ limitations under the License.
20
20
21
21
# find
22
22
23
- > Return the first element in an ndarray which pass a test implemented by a predicate function.
23
+ > Return the first element in an ndarray which passes a test implemented by a predicate function.
24
24
25
25
<section class =" intro " >
26
26
@@ -42,14 +42,14 @@ var find = require( '@stdlib/ndarray/base/find' );
42
42
43
43
#### find( arrays, predicate\[ , thisArg] )
44
44
45
- Returns the first element in an ndarray which pass a test implemented by a predicate function.
45
+ Returns the first element in an ndarray which passes a test implemented by a predicate function.
46
46
47
47
<!-- eslint-disable max-len -->
48
48
49
49
``` javascript
50
50
var Float64Array = require ( ' @stdlib/array/float64' );
51
51
52
- function clbk ( value ) {
52
+ function isEven ( value ) {
53
53
return value % 2.0 === 0.0 ;
54
54
}
55
55
@@ -65,16 +65,6 @@ var sx = [ 4, 4, 1 ];
65
65
// Define the index offset:
66
66
var ox = 0 ;
67
67
68
- // Create the sentinel value ndarray-like object:
69
- var sentinelValue = {
70
- ' dtype' : ' float64' ,
71
- ' data' : new Float64Array ( [ NaN ] ),
72
- ' shape' : [],
73
- ' strides' : [ 0 ],
74
- ' offset' : 0 ,
75
- ' order' : ' row-major'
76
- };
77
-
78
68
// Create the input ndarray-like object:
79
69
var x = {
80
70
' dtype' : ' float64' ,
@@ -85,14 +75,24 @@ var x = {
85
75
' order' : ' row-major'
86
76
};
87
77
78
+ // Create the sentinel value ndarray-like object:
79
+ var sentinelValue = {
80
+ ' dtype' : ' float64' ,
81
+ ' data' : new Float64Array ( [ NaN ] ),
82
+ ' shape' : [],
83
+ ' strides' : [ 0 ],
84
+ ' offset' : 0 ,
85
+ ' order' : ' row-major'
86
+ };
87
+
88
88
// Perform reduction:
89
- var out = find ( [ x, sentinelValue ], clbk );
89
+ var out = find ( [ x, sentinelValue ], isEven );
90
90
// returns 2.0
91
91
```
92
92
93
93
The function accepts the following arguments:
94
94
95
- - ** arrays** : array-like object containing an input ndarray and a zero-dimensional sentinel value ndarray.
95
+ - ** arrays** : array-like object containing an input ndarray and a zero-dimensional ndarray containing a sentinel value which should be returned when no element in an input ndarray passes a test implemented by the predicate function .
96
96
- ** predicate** : predicate function.
97
97
- ** thisArg** : predicate function execution context (_ optional_ ).
98
98
@@ -118,7 +118,7 @@ To set the predicate function execution context, provide a `thisArg`.
118
118
``` javascript
119
119
var Float64Array = require ( ' @stdlib/array/float64' );
120
120
121
- function clbk ( value ) {
121
+ function isEven ( value ) {
122
122
this .count += 1 ;
123
123
return value % 2.0 === 0.0 ;
124
124
}
@@ -135,16 +135,6 @@ var sx = [ 4, 4, 1 ];
135
135
// Define the index offset:
136
136
var ox = 0 ;
137
137
138
- // Create the sentinel value ndarray-like object:
139
- var sentinelValue = {
140
- ' dtype' : ' float64' ,
141
- ' data' : new Float64Array ( [ NaN ] ),
142
- ' shape' : [],
143
- ' strides' : [ 0 ],
144
- ' offset' : 0 ,
145
- ' order' : ' row-major'
146
- };
147
-
148
138
// Create the input ndarray-like object:
149
139
var x = {
150
140
' dtype' : ' float64' ,
@@ -155,12 +145,22 @@ var x = {
155
145
' order' : ' row-major'
156
146
};
157
147
148
+ // Create the sentinel value ndarray-like object:
149
+ var sentinelValue = {
150
+ ' dtype' : ' float64' ,
151
+ ' data' : new Float64Array ( [ NaN ] ),
152
+ ' shape' : [],
153
+ ' strides' : [ 0 ],
154
+ ' offset' : 0 ,
155
+ ' order' : ' row-major'
156
+ };
157
+
158
158
var ctx = {
159
159
' count' : 0
160
160
};
161
161
162
162
// Test elements:
163
- var out = find ( [ x, sentinelValue ], clbk , ctx );
163
+ var out = find ( [ x, sentinelValue ], isEven , ctx );
164
164
// returns 2.0
165
165
166
166
var count = ctx .count ;
@@ -193,7 +193,7 @@ var Float64Array = require( '@stdlib/array/float64' );
193
193
var ndarray2array = require ( ' @stdlib/ndarray/base/to-array' );
194
194
var find = require ( ' @stdlib/ndarray/base/find' );
195
195
196
- function clbk ( value ) {
196
+ function isEven ( value ) {
197
197
return value % 2.0 === 0.0 ;
198
198
}
199
199
@@ -219,7 +219,7 @@ var sv = {
219
219
};
220
220
console .log ( ' Sentinel Value: %d' , sv .data [ 0 ] );
221
221
222
- var out = find ( [ x, sv ], clbk );
222
+ var out = find ( [ x, sv ], isEven );
223
223
console .log ( out );
224
224
```
225
225
0 commit comments