@@ -202,39 +202,81 @@ tape( 'the function calculates the maximum value of an array (array-like object)
202
202
} ) ;
203
203
204
204
tape ( 'the function supports providing a callback execution context' , function test ( t ) {
205
+ var expected ;
206
+ var indices ;
207
+ var values ;
208
+ var arrays ;
205
209
var ctx ;
206
210
var x ;
207
211
208
212
x = [ 1.0 , 2.0 , 3.0 , 4.0 , 5.0 ] ;
209
213
ctx = {
210
214
'count' : 0
211
215
} ;
216
+ indices = [ ] ;
217
+ values = [ ] ;
218
+ arrays = [ ] ;
212
219
maxBy ( x , accessor , ctx ) ;
213
220
214
221
t . strictEqual ( ctx . count , x . length , 'returns expected value' ) ;
222
+
223
+ expected = [ 0 , 1 , 2 , 3 , 4 ] ;
224
+ t . deepEqual ( indices , expected , 'returns expected value' ) ;
225
+
226
+ expected = [ 1.0 , 2.0 , 3.0 , 4.0 , 5.0 ] ;
227
+ t . deepEqual ( values , expected , 'returns expected value' ) ;
228
+
229
+ expected = [ x , x , x , x , x ] ;
230
+ t . deepEqual ( arrays , expected , 'returns expected value' ) ;
231
+
215
232
t . end ( ) ;
216
233
217
- function accessor ( v ) {
234
+ function accessor ( v , idx , arr ) {
218
235
this . count += 1 ; // eslint-disable-line no-invalid-this
236
+ indices . push ( idx ) ;
237
+ values . push ( v ) ;
238
+ arrays . push ( arr ) ;
219
239
return v * 2.0 ;
220
240
}
221
241
} ) ;
222
242
223
243
tape ( 'the function supports providing a callback execution context (accessors)' , function test ( t ) {
244
+ var expected ;
245
+ var indices ;
246
+ var values ;
247
+ var arrays ;
224
248
var ctx ;
249
+ var ax ;
225
250
var x ;
226
251
227
252
x = [ 1.0 , 2.0 , 3.0 , 4.0 , 5.0 ] ;
253
+ ax = toAccessorArray ( x ) ;
228
254
ctx = {
229
255
'count' : 0
230
256
} ;
231
- maxBy ( toAccessorArray ( x ) , accessor , ctx ) ;
257
+ indices = [ ] ;
258
+ values = [ ] ;
259
+ arrays = [ ] ;
260
+ maxBy ( ax , accessor , ctx ) ;
232
261
233
262
t . strictEqual ( ctx . count , x . length , 'returns expected value' ) ;
263
+
264
+ expected = [ 0 , 1 , 2 , 3 , 4 ] ;
265
+ t . deepEqual ( indices , expected , 'returns expected value' ) ;
266
+
267
+ expected = [ 1.0 , 2.0 , 3.0 , 4.0 , 5.0 ] ;
268
+ t . deepEqual ( values , expected , 'returns expected value' ) ;
269
+
270
+ expected = [ ax , ax , ax , ax , ax ] ;
271
+ t . deepEqual ( arrays , expected , 'returns expected value' ) ;
272
+
234
273
t . end ( ) ;
235
274
236
- function accessor ( v ) {
275
+ function accessor ( v , idx , arr ) {
237
276
this . count += 1 ; // eslint-disable-line no-invalid-this
277
+ indices . push ( idx ) ;
278
+ values . push ( v ) ;
279
+ arrays . push ( arr ) ;
238
280
return v * 2.0 ;
239
281
}
240
282
} ) ;
0 commit comments