Skip to content

Commit 1cc23a6

Browse files
committed
chore: clean-up
1 parent f996caa commit 1cc23a6

File tree

3 files changed

+61
-46
lines changed

3 files changed

+61
-46
lines changed

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

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -338,27 +338,6 @@ v = arr.at( -100 );
338338
// returns undefined
339339
```
340340

341-
<a name="method-index-of"></a>
342-
343-
#### TypedArrayFE.prototype.indexOf( searchElement\[, fromIndex] )
344-
345-
Returns the first index at which a given element can be found in the typed array, or `-1` if it is not present.
346-
347-
```javascript
348-
var Float64ArrayFE = fixedEndianFactory( 'float64' );
349-
350-
var arr = new Float64ArrayFE( 'little-endian', [ 1.0, 2.0, 3.0, 4.0 ] );
351-
352-
var idx = arr.indexOf( 2.0 );
353-
// returns 1
354-
355-
idx = arr.indexOf( 5.0 );
356-
// returns -1
357-
358-
idx = arr.indexOf( 3.0, 3 );
359-
// returns -1
360-
```
361-
362341
<a name="method-every"></a>
363342

364343
#### TypedArrayFE.prototype.every( predicate\[, thisArg] )
@@ -496,6 +475,38 @@ var v = arr.get( 100 );
496475
// returns undefined
497476
```
498477

478+
<a name="method-index-of"></a>
479+
480+
#### TypedArrayFE.prototype.indexOf( searchElement\[, fromIndex] )
481+
482+
Returns the first index at which a given element can be found.
483+
484+
```javascript
485+
var Float64ArrayFE = fixedEndianFactory( 'float64' );
486+
487+
var arr = new Float64ArrayFE( 'little-endian', [ 1.0, 2.0, 3.0, 4.0, 2.0 ] );
488+
489+
var idx = arr.indexOf( 2.0 );
490+
// returns 1
491+
492+
idx = arr.indexOf( 2.0, 2 );
493+
// returns 4
494+
495+
idx = arr.indexOf( 2.0, -4 );
496+
// returns 1
497+
```
498+
499+
If `searchElement` is not present in the array, the method returns `-1`.
500+
501+
```javascript
502+
var Float64ArrayFE = fixedEndianFactory( 'float64' );
503+
504+
var arr = new Float64ArrayFE( 'little-endian', [ 1.0, 2.0, 3.0, 4.0, 2.0 ] );
505+
506+
var idx = arr.indexOf( 5.0 );
507+
// returns -1
508+
```
509+
499510
<a name="method-set"></a>
500511

501512
#### TypedArrayFE.prototype.set( arr\[, offset] )

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

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -624,50 +624,42 @@ function factory( dtype ) { // eslint-disable-line max-lines-per-function, stdli
624624
/**
625625
* Returns the index of the first occurrence of a given element.
626626
*
627+
* @private
627628
* @name indexOf
628629
* @memberof TypedArray.prototype
629630
* @type {Function}
630631
* @param {*} searchElement - element to search for
631-
* @param {integer} fromIndex - index to start the search from (optional)
632+
* @param {integer} [fromIndex=0] - starting index (inclusive)
632633
* @throws {TypeError} `this` must be a typed array instance
633-
* @returns {integer} index of the first occurrence of the element, or -1 if not found
634+
* @throws {TypeError} second argument must be an integer
635+
* @returns {integer} index or -1
634636
*/
635637
setReadOnly( TypedArray.prototype, 'indexOf', function indexOf( searchElement, fromIndex ) {
636-
var len;
637638
var buf;
638639
var i;
639640

640641
if ( !isTypedArray( this ) ) {
641642
throw new TypeError( format( 'invalid invocation. `this` is not %s %s.', CHAR2ARTICLE[ dtype[0] ], CTOR_NAME ) );
642643
}
643-
644-
len = this._length;
645-
646644
if ( arguments.length > 1 ) {
647645
if ( !isInteger( fromIndex ) ) {
648646
throw new TypeError( format( 'invalid argument. Second argument must be an integer. Value: `%s`.', fromIndex ) );
649647
}
650648
if ( fromIndex < 0 ) {
651-
fromIndex += len;
649+
fromIndex += this._length;
652650
if ( fromIndex < 0 ) {
653651
fromIndex = 0;
654652
}
655653
}
656-
if ( fromIndex >= len ) {
657-
return -1;
658-
}
659654
} else {
660655
fromIndex = 0;
661656
}
662-
663657
buf = this._buffer;
664-
665-
for ( i = fromIndex; i < len; i++ ) {
658+
for ( i = fromIndex; i < this._length; i++ ) {
666659
if ( buf[ GETTER ]( i * BYTES_PER_ELEMENT, this._isLE ) === searchElement ) {
667660
return i;
668661
}
669662
}
670-
671663
return -1;
672664
});
673665

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

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ tape( 'the method throws an error if invoked with a `this` context which is not
8080
}
8181
});
8282

83-
tape( 'the method throws an error if provided `fromIndex` argument which is not an integer', function test( t ) {
83+
tape( 'the method throws an error if provided a second argument which is not an integer', function test( t ) {
8484
var values;
8585
var ctor;
8686
var arr;
@@ -113,7 +113,7 @@ tape( 'the method throws an error if provided `fromIndex` argument which is not
113113
}
114114
});
115115

116-
tape( 'the method returns `-1` if provided fromIndex argument which exceeds array dimensions', function test( t ) {
116+
tape( 'the method returns `-1` if provided a second argument which exceeds array dimensions', function test( t ) {
117117
var ctor;
118118
var arr;
119119
var v;
@@ -122,7 +122,7 @@ tape( 'the method returns `-1` if provided fromIndex argument which exceeds arra
122122
ctor = factory( 'float64' );
123123
arr = new ctor( 'little-endian', [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 ] );
124124

125-
for ( i = arr.length; i < arr.length + 5; i++ ) {
125+
for ( i = arr.length; i < arr.length+5; i++ ) {
126126
v = arr.indexOf( 1.0, i );
127127
t.strictEqual( v, -1, 'returns expected value' );
128128
}
@@ -138,12 +138,12 @@ tape( 'the method returns `-1` if operating on an empty array', function test( t
138138
arr = new ctor( 'little-endian', [] );
139139

140140
v = arr.indexOf( 1.0 );
141-
t.strictEqual( v, -1, 'returns -1 for an empty array' );
141+
t.strictEqual( v, -1, 'returns expected value' );
142142

143143
t.end();
144144
});
145145

146-
tape( 'the method returns `-1` if element not found', function test( t ) {
146+
tape( 'the method returns `-1` if a search element is not found', function test( t ) {
147147
var ctor;
148148
var arr;
149149
var v;
@@ -152,12 +152,12 @@ tape( 'the method returns `-1` if element not found', function test( t ) {
152152
arr = new ctor( 'little-endian', [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );
153153

154154
v = arr.indexOf( 10.0 );
155-
t.strictEqual( v, -1, 'returns -1 when element is not found' );
155+
t.strictEqual( v, -1, 'returns expected value' );
156156

157157
t.end();
158158
});
159159

160-
tape( 'the method returns the index of the first match if element is found', function test( t ) {
160+
tape( 'the method returns the index of the first match if an element is found', function test( t ) {
161161
var ctor;
162162
var arr;
163163
var v;
@@ -166,7 +166,7 @@ tape( 'the method returns the index of the first match if element is found', fun
166166
arr = new ctor( 'little-endian', [ 1.0, 2.0, 3.0, 4.0, 2.0 ] );
167167

168168
v = arr.indexOf( 2.0 );
169-
t.strictEqual( v, 1, 'returns index of the first match when the element is found' );
169+
t.strictEqual( v, 1, 'returns expected value' );
170170

171171
t.end();
172172
});
@@ -179,8 +179,14 @@ tape( 'the method supports specifying a starting search index', function test( t
179179
ctor = factory( 'float64' );
180180
arr = new ctor( 'little-endian', [ 1.0, 2.0, 3.0, 4.0, 2.0 ] );
181181

182+
v = arr.indexOf( 2.0, 0 );
183+
t.strictEqual( v, 2, 'returns expected value' );
184+
182185
v = arr.indexOf( 2.0, 2 );
183-
t.strictEqual( v, 4, 'returns index of the match starting from the specified index' );
186+
t.strictEqual( v, 4, 'returns expected value' );
187+
188+
v = arr.indexOf( 1.0, 4 );
189+
t.strictEqual( v, -1, 'returns expected value' );
184190

185191
t.end();
186192
});
@@ -194,7 +200,10 @@ tape( 'the method supports specifying a starting search index (negative)', funct
194200
arr = new ctor( 'little-endian', [ 1.0, 2.0, 3.0, 4.0, 2.0 ] );
195201

196202
v = arr.indexOf( 2.0, -3 );
197-
t.strictEqual( v, 4, 'returns index of the match starting from the resolved negative index' );
203+
t.strictEqual( v, 4, 'returns expected value' );
204+
205+
v = arr.indexOf( 1.0, -3 );
206+
t.strictEqual( v, -1, 'returns expected value' );
198207

199208
t.end();
200209
});
@@ -208,7 +217,10 @@ tape( 'when provided a starting index which resolves to an index less than zero,
208217
arr = new ctor( 'little-endian', [ 1.0, 2.0, 3.0, 4.0, 2.0 ] );
209218

210219
v = arr.indexOf( 2.0, -10 );
211-
t.strictEqual( v, 1, 'returns index of the match starting from the first array element when starting index resolves to less than zero' );
220+
t.strictEqual( v, 1, 'returns expected value' );
221+
222+
v = arr.indexOf( 1.0, -10 );
223+
t.strictEqual( v, 0, 'returns expected value' );
212224

213225
t.end();
214226
});

0 commit comments

Comments
 (0)