Skip to content

Commit

Permalink
Auto-generated commit
Browse files Browse the repository at this point in the history
  • Loading branch information
stdlib-bot committed Dec 20, 2023
1 parent a244f2b commit b354a99
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 18 deletions.
10 changes: 8 additions & 2 deletions complex64/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -900,7 +900,7 @@ Returns the first index at which a given element can be found.
```javascript
var Complex64 = require( '@stdlib/complex/float32' );

var arr = new Complex64Array( 10 );
var arr = new Complex64Array( 5 );

arr.set( [ 1.0, -1.0 ], 0 );
arr.set( [ 2.0, -2.0 ], 1 );
Expand All @@ -913,6 +913,9 @@ var idx = arr.indexOf( new Complex64( 3.0, -3.0 ) );

idx = arr.indexOf( new Complex64( 2.0, -2.0 ), 2 );
// returns 4

idx = arr.indexOf( new Complex64( 4.0, -4.0 ), -3 );
// returns 3
```

If `searchElement` is not present in the array, the method returns `-1`.
Expand Down Expand Up @@ -941,7 +944,7 @@ Returns the last index at which a given element can be found.
```javascript
var Complex64 = require( '@stdlib/complex/float32' );

var arr = new Complex64Array( 10 );
var arr = new Complex64Array( 5 );

arr.set( [ 1.0, -1.0 ], 0 );
arr.set( [ 2.0, -2.0 ], 1 );
Expand All @@ -954,6 +957,9 @@ var idx = arr.lastIndexOf( new Complex64( 3.0, -3.0 ) );

idx = arr.lastIndexOf( new Complex64( 2.0, -2.0 ), 2 );
// returns 1

idx = arr.lastIndexOf( new Complex64( 4.0, -4.0 ), -1 );
// returns 3
```

If `searchElement` is not present in the array, the method returns `-1`.
Expand Down
10 changes: 7 additions & 3 deletions complex64/docs/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,18 +371,22 @@ declare class Complex64Array implements Complex64ArrayInterface {
* @returns index or -1
*
* @example
* var arr = new Complex64Array( 10 );
* var arr = new Complex64Array( 5 );
*
* arr.set( [ 1.0, 1.0 ], 0 );
* arr.set( [ 2.0, 2.0 ], 1 );
* arr.set( [ 3.0, 3.0 ], 2 );
* arr.set( [ 2.0, 2.0 ], 3 );
* arr.set( [ 5.0, 5.0 ], 4 );
*
* var idx = arr.indexOf( new Complex64( [ 2.0, 2.0 ] ) );
* // returns 1
*
* idx = arr.indexOf( new Complex64( [ 2.0, 2.0 ] ), 2 );
* // returns 3
*
* idx = arr.indexOf( new Complex64( [ 2.0, 2.0 ] ), -3 );
* // returns 3
*/
indexOf( searchElement: ComplexLike, fromIndex?: number ): number;

Expand Down Expand Up @@ -410,8 +414,8 @@ declare class Complex64Array implements Complex64ArrayInterface {
* idx = arr.lastIndexOf( new Complex64( 3.0, -3.0 ), 3 );
* // returns 2
*
* idx = arr.lastIndexOf( new Complex64( 5.0, -5.0 ), 3 );
* // returns -1
* idx = arr.lastIndexOf( new Complex64( 2.0, -2.0 ), -3 );
* // returns 1
*/
lastIndexOf( searchElement: ComplexLike, fromIndex?: number ): number;

Expand Down
26 changes: 20 additions & 6 deletions complex64/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -981,7 +981,7 @@ setReadOnly( Complex64Array.prototype, 'get', function get( idx ) {
* @param {integer} [fromIndex=0] - starting index (inclusive)
* @throws {TypeError} `this` must be a complex number array
* @throws {TypeError} first argument must be a complex number
* @throws {TypeError} second argument must be an nonnegative integer
* @throws {TypeError} second argument must be an integer
* @returns {integer} index or -1
*
* @example
Expand All @@ -1000,6 +1000,9 @@ setReadOnly( Complex64Array.prototype, 'get', function get( idx ) {
*
* idx = arr.indexOf( new Complex64( 3.0, -3.0 ), 3 );
* // returns -1
*
* idx = arr.indexOf( new Complex64( 4.0, -4.0 ), -3 );
* // returns -1
*/
setReadOnly( Complex64Array.prototype, 'indexOf', function indexOf( searchElement, fromIndex ) {
var buf;
Expand All @@ -1014,8 +1017,14 @@ setReadOnly( Complex64Array.prototype, 'indexOf', function indexOf( searchElemen
throw new TypeError( format( 'invalid argument. First argument must be a complex number. Value: `%s`.', searchElement ) );
}
if ( arguments.length > 1 ) {
if ( !isNonNegativeInteger( fromIndex ) ) {
throw new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', fromIndex ) );
if ( !isInteger( fromIndex ) ) {
throw new TypeError( format( 'invalid argument. Second argument must be an integer. Value: `%s`.', fromIndex ) );
}
if ( fromIndex < 0 ) {
fromIndex += this._length;
if ( fromIndex < 0 ) {
fromIndex = 0;
}
}
} else {
fromIndex = 0;
Expand All @@ -1042,7 +1051,7 @@ setReadOnly( Complex64Array.prototype, 'indexOf', function indexOf( searchElemen
* @param {integer} [fromIndex] - index at which to start searching backward (inclusive)
* @throws {TypeError} `this` must be a complex number array
* @throws {TypeError} first argument must be a complex number
* @throws {TypeError} second argument must be an nonnegative integer
* @throws {TypeError} second argument must be an integer
* @returns {integer} index or -1
*
* @example
Expand All @@ -1064,6 +1073,9 @@ setReadOnly( Complex64Array.prototype, 'indexOf', function indexOf( searchElemen
*
* idx = arr.lastIndexOf( new Complex64( 5.0, -5.0 ), 3 );
* // returns -1
*
* idx = arr.lastIndexOf( new Complex64( 2.0, -2.0 ), -3 );
* // returns 1
*/
setReadOnly( Complex64Array.prototype, 'lastIndexOf', function lastIndexOf( searchElement, fromIndex ) {
var buf;
Expand All @@ -1078,11 +1090,13 @@ setReadOnly( Complex64Array.prototype, 'lastIndexOf', function lastIndexOf( sear
throw new TypeError( format( 'invalid argument. First argument must be a complex number. Value: `%s`.', searchElement ) );
}
if ( arguments.length > 1 ) {
if ( !isNonNegativeInteger( fromIndex ) ) {
throw new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', fromIndex ) );
if ( !isInteger( fromIndex ) ) {
throw new TypeError( format( 'invalid argument. Second argument must be an integer. Value: `%s`.', fromIndex ) );
}
if ( fromIndex >= this._length ) {
fromIndex = this._length - 1;
} else if ( fromIndex < 0 ) {
fromIndex += this._length;
}
} else {
fromIndex = this._length - 1;
Expand Down
41 changes: 39 additions & 2 deletions complex64/test/test.index_of.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ tape( 'the method throws an error if provided a first argument which is not a co
}
});

tape( 'the method throws an error if provided a second argument which is not a nonnegative integer', function test( t ) {
tape( 'the method throws an error if provided a second argument which is not an integer', function test( t ) {
var values;
var arr;
var i;
Expand All @@ -112,7 +112,6 @@ tape( 'the method throws an error if provided a second argument which is not a n

values = [
'5',
-5,
3.14,
NaN,
true,
Expand Down Expand Up @@ -203,3 +202,41 @@ tape( 'the method supports specifying a starting search index', function test( t
t.strictEqual( idx, -1, 'returns expected value' );
t.end();
});

tape( 'the method supports specifying a starting search index (negative)', function test( t ) {
var idx;
var arr;

arr = new Complex64Array( 5 );
arr.set( [ 1.0, 1.0 ], 0 );
arr.set( [ 2.0, 2.0 ], 1 );
arr.set( [ 3.0, 3.0 ], 2 );
arr.set( [ 2.0, 2.0 ], 3 );
arr.set( [ 2.0, 2.0 ], 4 );

idx = arr.indexOf( new Complex64( 2.0, 2.0 ), -5 );
t.strictEqual( idx, 1, 'returns expected value' );

idx = arr.indexOf( new Complex64( 4.0, 4.0 ), -2 );
t.strictEqual( idx, -1, 'returns expected value' );
t.end();
});

tape( 'when provided a starting index which resolves to an index which is less than zero, the method searches from the first array element', function test( t ) {
var idx;
var arr;

arr = new Complex64Array( 5 );
arr.set( [ 1.0, 1.0 ], 0 );
arr.set( [ 2.0, 2.0 ], 1 );
arr.set( [ 3.0, 3.0 ], 2 );
arr.set( [ 2.0, 2.0 ], 3 );
arr.set( [ 2.0, 2.0 ], 4 );

idx = arr.indexOf( new Complex64( 2.0, 2.0 ), -10 );
t.strictEqual( idx, 1, 'returns expected value' );

idx = arr.indexOf( new Complex64( 4.0, 4.0 ), -10 );
t.strictEqual( idx, -1, 'returns expected value' );
t.end();
});
41 changes: 39 additions & 2 deletions complex64/test/test.last_index_of.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ tape( 'the method throws an error if provided a first argument which is not a co
}
});

tape( 'the method throws an error if provided a second argument which is not a nonnegative integer', function test( t ) {
tape( 'the method throws an error if provided a second argument which is not an integer', function test( t ) {
var values;
var arr;
var i;
Expand All @@ -112,7 +112,6 @@ tape( 'the method throws an error if provided a second argument which is not a n

values = [
'5',
-5,
3.14,
NaN,
true,
Expand Down Expand Up @@ -193,3 +192,41 @@ tape( 'the method supports specifying a starting search index', function test( t
t.strictEqual( idx, -1, 'returns expected value' );
t.end();
});

tape( 'the method supports specifying a starting search index (negative)', function test( t ) {
var idx;
var arr;

arr = new Complex64Array( 5 );
arr.set( [ 1.0, 1.0 ], 0 );
arr.set( [ 2.0, 2.0 ], 1 );
arr.set( [ 3.0, 3.0 ], 2 );
arr.set( [ 2.0, 2.0 ], 3 );
arr.set( [ 2.0, 2.0 ], 4 );

idx = arr.lastIndexOf( new Complex64( 2.0, 2.0 ), -3 );
t.strictEqual( idx, 1, 'returns expected value' );

idx = arr.lastIndexOf( new Complex64( 3.0, 3.0 ), -1 );
t.strictEqual( idx, 2, 'returns expected value' );
t.end();
});

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 ) {
var idx;
var arr;

arr = new Complex64Array( 5 );
arr.set( [ 1.0, 1.0 ], 0 );
arr.set( [ 2.0, 2.0 ], 1 );
arr.set( [ 3.0, 3.0 ], 2 );
arr.set( [ 2.0, 2.0 ], 3 );
arr.set( [ 2.0, 2.0 ], 4 );

idx = arr.lastIndexOf( new Complex64( 2.0, 2.0 ), 10 );
t.strictEqual( idx, 4, 'returns expected value' );

idx = arr.lastIndexOf( new Complex64( 4.0, 4.0 ), 10 );
t.strictEqual( idx, -1, 'returns expected value' );
t.end();
});
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

Loading

0 comments on commit b354a99

Please sign in to comment.