@@ -1329,6 +1329,78 @@ setReadOnly( Complex128Array.prototype, 'indexOf', function indexOf( searchEleme
1329
1329
return - 1 ;
1330
1330
} ) ;
1331
1331
1332
+ /**
1333
+ * Returns the last index at which a given element can be found.
1334
+ *
1335
+ * @name lastIndexOf
1336
+ * @memberof Complex128Array.prototype
1337
+ * @type {Function }
1338
+ * @param {Complex128 } searchElement - element to find
1339
+ * @param {integer } [fromIndex] - index at which to start searching backward (inclusive)
1340
+ * @throws {TypeError } `this` must be a complex number array
1341
+ * @throws {TypeError } first argument must be a complex number
1342
+ * @throws {TypeError } second argument must be an integer
1343
+ * @returns {integer } index or -1
1344
+ *
1345
+ * @example
1346
+ * var Complex128 = require( '@stdlib/complex/float64' );
1347
+ *
1348
+ * var arr = new Complex128Array( 5 );
1349
+ *
1350
+ * arr.set( [ 1.0, -1.0 ], 0 );
1351
+ * arr.set( [ 2.0, -2.0 ], 1 );
1352
+ * arr.set( [ 3.0, -3.0 ], 2 );
1353
+ * arr.set( [ 4.0, -4.0 ], 3 );
1354
+ * arr.set( [ 3.0, -3.0 ], 4 );
1355
+ *
1356
+ * var idx = arr.lastIndexOf( new Complex128( 3.0, -3.0 ) );
1357
+ * // returns 4
1358
+ *
1359
+ * idx = arr.lastIndexOf( new Complex128( 3.0, -3.0 ), 3 );
1360
+ * // returns 2
1361
+ *
1362
+ * idx = arr.lastIndexOf( new Complex128( 5.0, -5.0 ), 3 );
1363
+ * // returns -1
1364
+ *
1365
+ * idx = arr.lastIndexOf( new Complex128( 2.0, -2.0 ), -3 );
1366
+ * // returns 1
1367
+ */
1368
+ setReadOnly ( Complex128Array . prototype , 'lastIndexOf' , function lastIndexOf ( searchElement , fromIndex ) {
1369
+ var buf ;
1370
+ var idx ;
1371
+ var re ;
1372
+ var im ;
1373
+ var i ;
1374
+ if ( ! isComplexArray ( this ) ) {
1375
+ throw new TypeError ( 'invalid invocation. `this` is not a complex number array.' ) ;
1376
+ }
1377
+ if ( ! isComplexLike ( searchElement ) ) {
1378
+ throw new TypeError ( format ( 'invalid argument. First argument must be a complex number. Value: `%s`.' , searchElement ) ) ;
1379
+ }
1380
+ if ( arguments . length > 1 ) {
1381
+ if ( ! isInteger ( fromIndex ) ) {
1382
+ throw new TypeError ( format ( 'invalid argument. Second argument must be an integer. Value: `%s`.' , fromIndex ) ) ;
1383
+ }
1384
+ if ( fromIndex >= this . _length ) {
1385
+ fromIndex = this . _length - 1 ;
1386
+ } else if ( fromIndex < 0 ) {
1387
+ fromIndex += this . _length ;
1388
+ }
1389
+ } else {
1390
+ fromIndex = this . _length - 1 ;
1391
+ }
1392
+ re = real ( searchElement ) ;
1393
+ im = imag ( searchElement ) ;
1394
+ buf = this . _buffer ;
1395
+ for ( i = fromIndex ; i >= 0 ; i -- ) {
1396
+ idx = 2 * i ;
1397
+ if ( re === buf [ idx ] && im === buf [ idx + 1 ] ) {
1398
+ return i ;
1399
+ }
1400
+ }
1401
+ return - 1 ;
1402
+ } ) ;
1403
+
1332
1404
/**
1333
1405
* Sets an array element.
1334
1406
*
0 commit comments