Skip to content

Commit 9798530

Browse files
committed
chore: minor clean-up
1 parent 7d8ab5a commit 9798530

File tree

4 files changed

+19
-7
lines changed

4 files changed

+19
-7
lines changed

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,7 @@ function factory( dtype ) { // eslint-disable-line max-lines-per-function, stdli
720720
* @memberof TypedArray.prototype
721721
* @type {Function}
722722
* @param {*} searchElement - element to search for
723-
* @param {integer} [fromIndex=this._length-1] - starting index (inclusive)
723+
* @param {integer} fromIndex - starting index (inclusive)
724724
* @throws {TypeError} `this` must be a typed array instance
725725
* @throws {TypeError} second argument must be an integer
726726
* @returns {integer} index or -1
@@ -736,14 +736,10 @@ function factory( dtype ) { // eslint-disable-line max-lines-per-function, stdli
736736
if ( !isInteger( fromIndex ) ) {
737737
throw new TypeError( format( 'invalid argument. Second argument must be an integer. Value: `%s`.', fromIndex ) );
738738
}
739-
if ( fromIndex < 0 ) {
740-
fromIndex += this._length;
741-
}
742-
if ( fromIndex < 0 ) {
743-
return -1;
744-
}
745739
if ( fromIndex >= this._length ) {
746740
fromIndex = this._length - 1;
741+
} else if ( fromIndex < 0 ) {
742+
fromIndex += this._length;
747743
}
748744
} else {
749745
fromIndex = this._length - 1;

lib/node_modules/@stdlib/array/fixed-endian-factory/test/test.last-index-of.js renamed to lib/node_modules/@stdlib/array/fixed-endian-factory/test/test.last_index_of.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,3 +204,19 @@ tape( 'the method supports specifying a starting search index (negative)', funct
204204

205205
t.end();
206206
});
207+
208+
tape( 'when the method is provided a starting index which resolves to an index which exceeds the maximum array index, the method searches from the last array element', function test( t ) {
209+
var ctor;
210+
var arr;
211+
var idx;
212+
213+
ctor = factory( 'float64' );
214+
arr = new ctor( 'little-endian', [ 1.0, 2.0, 3.0, 4.0, 2.0 ] );
215+
216+
idx = arr.lastIndexOf( 2.0, 10 );
217+
t.strictEqual( idx, 4, 'returns expected value' );
218+
219+
idx = arr.lastIndexOf( 5.0, 10 );
220+
t.strictEqual( idx, -1, 'returns expected value' );
221+
t.end();
222+
});

0 commit comments

Comments
 (0)