Skip to content

Commit 3ae887b

Browse files
committed
style: made minor changes in array/fixed-endian-factoy
1 parent d648fa5 commit 3ae887b

File tree

4 files changed

+23
-25
lines changed

4 files changed

+23
-25
lines changed

lib/node_modules/@stdlib/array/fixed-endian-factory/README.md

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -388,13 +388,12 @@ var count = context.count;
388388

389389
<a name="method-find-index"></a>
390390

391-
#### TypedArrayFE.prototype.findIndex( callbackFn\[, thisArg] )
391+
#### TypedArrayFE.prototype.findIndex( predicate\[, thisArg] )
392392

393-
Returns the index of the first element in a typed array that satisfies the provided testing function.
394-
If no element satisfies function, return -1.
393+
Returns the index of the first element in a typed array for which a predicate function returns a truthy value.
395394

396395
```javascript
397-
function greaterthantwo( v ) {
396+
function predicate( v ) {
398397
return ( v > 2.0 );
399398
}
400399

@@ -406,11 +405,11 @@ arr.set( 1.5, 0 );
406405
arr.set( 2.5, 1 );
407406
arr.set( 3.5, 2 );
408407

409-
var idx = arr.findIndex( greaterthantwo );
408+
var idx = arr.findIndex( predicate );
410409
// returns 1
411410
```
412411

413-
The invoked function is provided three arguments:
412+
The `predicate` function is provided three arguments:
414413

415414
- **value**: current array element.
416415
- **index**: current array element index.
@@ -419,9 +418,9 @@ The invoked function is provided three arguments:
419418
To set the function execution context, provide a `thisArg`.
420419

421420
```javascript
422-
function fcn( v, i ) {
421+
function predicate( v, i ) {
423422
this.count += 1;
424-
return (v === 2.0);
423+
return ( v === 2.0 );
425424
}
426425

427426
var Float64ArrayFE = fixedEndianFactory( 'float64' );
@@ -436,7 +435,7 @@ arr.set( 1.0, 0 );
436435
arr.set( 2.0, 1 );
437436
arr.set( 3.0, 2 );
438437

439-
arr.findIndex( fcn, context );
438+
arr.findIndex( predicate, context );
440439

441440
var count = context.count;
442441
// returns 2

lib/node_modules/@stdlib/array/fixed-endian-factory/benchmark/benchmark.find_index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,6 @@ bench( pkg+':findIndex', function benchmark( b ) {
3838
arr = new ctor( 'little-endian', [ 1.0, 2.0, 3.0, 4.0 ] );
3939
idx = arr.findIndex( predicate );
4040

41-
function predicate( v ) {
42-
return ( v === 3.0 );
43-
}
44-
4541
b.tic();
4642
for ( i = 0; i < b.iterations; i++ ) {
4743
idx = arr.findIndex( predicate );
@@ -55,4 +51,8 @@ bench( pkg+':findIndex', function benchmark( b ) {
5551
}
5652
b.pass( 'benchmark finished' );
5753
b.end();
54+
55+
function predicate( v ) {
56+
return ( v === 3.0 );
57+
}
5858
});

lib/node_modules/@stdlib/array/fixed-endian-factory/benchmark/benchmark.find_index.length.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ var Float64ArrayFE = factory( 'float64' );
4343
* @returns {Function} benchmark function
4444
*/
4545
function createBenchmark( len ) {
46-
var arr = new Float64ArrayFE( 'little-endian', zeroTo(len));
46+
var arr = new Float64ArrayFE( 'little-endian', zeroTo( len ) );
4747
return benchmark;
4848

4949
/**
@@ -58,7 +58,7 @@ function createBenchmark( len ) {
5858

5959
b.tic();
6060
for ( i = 0; i < b.iterations; i++ ) {
61-
idx=arr.findIndex( callback );
61+
idx = arr.findIndex( callback );
6262
if ( typeof idx !== 'number' ) {
6363
b.fail( 'should return an integer' );
6464
}
@@ -99,7 +99,7 @@ function main() {
9999
for ( i = min; i <= max; i++ ) {
100100
len = pow( 10, i );
101101
f = createBenchmark( len );
102-
bench( pkg+':forEach:len='+len, f );
102+
bench( pkg+':findIndex:len='+len, f );
103103
}
104104
}
105105

lib/node_modules/@stdlib/array/fixed-endian-factory/lib/main.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -570,36 +570,35 @@ function factory( dtype ) { // eslint-disable-line max-lines-per-function, stdli
570570
});
571571

572572
/**
573-
* Invokes a function once for each array element.
573+
* Returns the index of the first element in an array for which a predicate function returns a truthy value.
574574
*
575575
* @name findIndex
576576
* @memberof TypedArray.prototype
577577
* @type {Function}
578-
* @param {Function} callbackFn - function to invoke
578+
* @param {Function} predicate - function to invoke
579579
* @param {*} [thisArg] - function invocation context
580580
* @throws {TypeError} `this` must be a typed array instance
581581
* @throws {TypeError} first argument must be a function
582+
* @returns {integer} index or -1
582583
*/
583-
setReadOnly( TypedArray.prototype, 'findIndex', function findIndex( fcn, thisArg ) {
584-
var result;
584+
setReadOnly( TypedArray.prototype, 'findIndex', function findIndex( predicate, thisArg ) {
585585
var buf;
586586
var i;
587587

588588
if ( !isTypedArray( this ) ) {
589589
throw new TypeError( format( 'invalid invocation. `this` is not %s %s.', CHAR2ARTICLE[ dtype[0] ], CTOR_NAME ) );
590590
}
591-
if ( !isFunction( fcn ) ) {
592-
throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', fcn ) );
591+
if ( !isFunction( predicate ) ) {
592+
throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', predicate ) );
593593
}
594594

595595
buf = this._buffer;
596596
for (i = 0; i < this._length; i++) {
597-
result = fcn.call(thisArg, buf[GETTER](i * BYTES_PER_ELEMENT, this._isLE), i, this);
598-
if (result) {
597+
if ( predicate.call(thisArg, buf[GETTER](i * BYTES_PER_ELEMENT, this._isLE), i, this ) ) {
599598
return i;
600599
}
601600
}
602-
return -1; // Not found
601+
return -1;
603602
});
604603

605604
/**

0 commit comments

Comments
 (0)