@stdlib/array-base-last-index-of 0.2.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/NOTICE +1 -1
- package/README.md +20 -30
- package/dist/index.js +3 -3
- package/dist/index.js.map +3 -3
- package/docs/types/index.d.ts +4 -5
- package/lib/index.js +1 -1
- package/lib/main.js +16 -41
- package/package.json +3 -3
package/NOTICE
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Copyright (c) 2016-
|
|
1
|
+
Copyright (c) 2016-2026 The Stdlib Authors.
|
package/README.md
CHANGED
|
@@ -63,14 +63,14 @@ npm install @stdlib/array-base-last-index-of
|
|
|
63
63
|
var lastIndexOf = require( '@stdlib/array-base-last-index-of' );
|
|
64
64
|
```
|
|
65
65
|
|
|
66
|
-
#### lastIndexOf( x, searchElement, fromIndex
|
|
66
|
+
#### lastIndexOf( x, searchElement, fromIndex )
|
|
67
67
|
|
|
68
68
|
Returns the index of the last element which equals a provided search element.
|
|
69
69
|
|
|
70
70
|
```javascript
|
|
71
71
|
var x = [ 1, 2, 3, 4, 5, 6 ];
|
|
72
72
|
|
|
73
|
-
var idx = lastIndexOf( x, 3, 5
|
|
73
|
+
var idx = lastIndexOf( x, 3, 5 );
|
|
74
74
|
// returns 2
|
|
75
75
|
```
|
|
76
76
|
|
|
@@ -79,16 +79,16 @@ If the function is unable to find an element which equals a provided search elem
|
|
|
79
79
|
```javascript
|
|
80
80
|
var x = [ 1, 2, 3, 4, 5, 6 ];
|
|
81
81
|
|
|
82
|
-
var idx = lastIndexOf( x, 7, 5
|
|
82
|
+
var idx = lastIndexOf( x, 7, 5 );
|
|
83
83
|
// returns -1
|
|
84
84
|
```
|
|
85
85
|
|
|
86
|
-
To begin searching from specific index, provide a `fromIndex` argument.
|
|
86
|
+
To begin searching from a specific index, provide a corresponding `fromIndex` argument.
|
|
87
87
|
|
|
88
88
|
```javascript
|
|
89
89
|
var x = [ 1, 1, 2, 1, 2, 3, 3 ];
|
|
90
90
|
|
|
91
|
-
var idx = lastIndexOf( x, 2, 3
|
|
91
|
+
var idx = lastIndexOf( x, 2, 3 );
|
|
92
92
|
// returns 2
|
|
93
93
|
```
|
|
94
94
|
|
|
@@ -97,22 +97,10 @@ If `fromIndex` is less than zero, the starting index is resolved relative to the
|
|
|
97
97
|
```javascript
|
|
98
98
|
var x = [ 1, 1, 2, 1, 2, 3, 3 ];
|
|
99
99
|
|
|
100
|
-
var idx = lastIndexOf( x, 2, -4
|
|
100
|
+
var idx = lastIndexOf( x, 2, -4 );
|
|
101
101
|
// returns 2
|
|
102
102
|
```
|
|
103
103
|
|
|
104
|
-
When searching for a search element, the function checks for strict equality. As a consequence, `NaN` values are considered distinct. In order to resolve the last element which is `NaN`, set the `equalNaNs` argument to `true`.
|
|
105
|
-
|
|
106
|
-
```javascript
|
|
107
|
-
var x = [ 1, 2, 3, NaN, 5, 6 ];
|
|
108
|
-
|
|
109
|
-
var idx = lastIndexOf( x, NaN, 5, false );
|
|
110
|
-
// returns -1
|
|
111
|
-
|
|
112
|
-
idx = lastIndexOf( x, NaN, 5, true );
|
|
113
|
-
// returns 3
|
|
114
|
-
```
|
|
115
|
-
|
|
116
104
|
</section>
|
|
117
105
|
|
|
118
106
|
<!-- /.usage -->
|
|
@@ -125,13 +113,15 @@ idx = lastIndexOf( x, NaN, 5, true );
|
|
|
125
113
|
|
|
126
114
|
- The function scans an input array from the starting index to the beginning of the array (i.e., backward).
|
|
127
115
|
|
|
128
|
-
- If provided an array-like object having a `lastIndexOf` method
|
|
116
|
+
- If provided an array-like object having a `lastIndexOf` method, the function defers execution to that method and assumes that the method API has the following signature:
|
|
129
117
|
|
|
130
118
|
```text
|
|
131
119
|
x.lastIndexOf( searchElement, fromIndex )
|
|
132
120
|
```
|
|
133
121
|
|
|
134
|
-
- If provided an array-like object without a `lastIndexOf` method
|
|
122
|
+
- If provided an array-like object without a `lastIndexOf` method, the function performs a linear scan and returns immediately upon finding a match.
|
|
123
|
+
|
|
124
|
+
- When searching for a search element, the function checks for equality using the strict equality operator `===`. As a consequence, `NaN` values are considered distinct, and `-0` and `+0` are considered the same.
|
|
135
125
|
|
|
136
126
|
</section>
|
|
137
127
|
|
|
@@ -150,19 +140,19 @@ var lastIndexOf = require( '@stdlib/array-base-last-index-of' );
|
|
|
150
140
|
|
|
151
141
|
var x = [ 'foo', 'bar', 'beep', 'boop', 'foo', 'bar' ];
|
|
152
142
|
|
|
153
|
-
var idx = lastIndexOf( x, 'beep', 5
|
|
143
|
+
var idx = lastIndexOf( x, 'beep', 5 );
|
|
154
144
|
// returns 2
|
|
155
145
|
|
|
156
|
-
idx = lastIndexOf( x, 'bop', 5
|
|
146
|
+
idx = lastIndexOf( x, 'bop', 5 );
|
|
157
147
|
// returns -1
|
|
158
148
|
|
|
159
|
-
idx = lastIndexOf( x, 'foo', 5
|
|
149
|
+
idx = lastIndexOf( x, 'foo', 5 );
|
|
160
150
|
// returns 4
|
|
161
151
|
|
|
162
|
-
idx = lastIndexOf( x, 'foo', -3
|
|
152
|
+
idx = lastIndexOf( x, 'foo', -3 );
|
|
163
153
|
// returns 0
|
|
164
154
|
|
|
165
|
-
idx = lastIndexOf( x, 'foo', -50
|
|
155
|
+
idx = lastIndexOf( x, 'foo', -50 );
|
|
166
156
|
// returns -1
|
|
167
157
|
```
|
|
168
158
|
|
|
@@ -212,7 +202,7 @@ See [LICENSE][stdlib-license].
|
|
|
212
202
|
|
|
213
203
|
## Copyright
|
|
214
204
|
|
|
215
|
-
Copyright © 2016-
|
|
205
|
+
Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors].
|
|
216
206
|
|
|
217
207
|
</section>
|
|
218
208
|
|
|
@@ -225,8 +215,8 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors].
|
|
|
225
215
|
[npm-image]: http://img.shields.io/npm/v/@stdlib/array-base-last-index-of.svg
|
|
226
216
|
[npm-url]: https://npmjs.org/package/@stdlib/array-base-last-index-of
|
|
227
217
|
|
|
228
|
-
[test-image]: https://github.com/stdlib-js/array-base-last-index-of/actions/workflows/test.yml/badge.svg?branch=v0.
|
|
229
|
-
[test-url]: https://github.com/stdlib-js/array-base-last-index-of/actions/workflows/test.yml?query=branch:v0.
|
|
218
|
+
[test-image]: https://github.com/stdlib-js/array-base-last-index-of/actions/workflows/test.yml/badge.svg?branch=v0.3.0
|
|
219
|
+
[test-url]: https://github.com/stdlib-js/array-base-last-index-of/actions/workflows/test.yml?query=branch:v0.3.0
|
|
230
220
|
|
|
231
221
|
[coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/array-base-last-index-of/main.svg
|
|
232
222
|
[coverage-url]: https://codecov.io/github/stdlib-js/array-base-last-index-of?branch=main
|
|
@@ -238,8 +228,8 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors].
|
|
|
238
228
|
|
|
239
229
|
-->
|
|
240
230
|
|
|
241
|
-
[chat-image]: https://img.shields.io/
|
|
242
|
-
[chat-url]: https://
|
|
231
|
+
[chat-image]: https://img.shields.io/badge/zulip-join_chat-brightgreen.svg
|
|
232
|
+
[chat-url]: https://stdlib.zulipchat.com
|
|
243
233
|
|
|
244
234
|
[stdlib]: https://github.com/stdlib-js/stdlib
|
|
245
235
|
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
"use strict";var
|
|
2
|
-
var
|
|
3
|
-
});var
|
|
1
|
+
"use strict";var a=function(r,t){return function(){return t||r((t={exports:{}}).exports,t),t.exports}};var s=a(function(q,u){
|
|
2
|
+
var f=require('@stdlib/assert-is-accessor-array/dist'),c=require('@stdlib/array-base-resolve-getter/dist');function l(r,t){return typeof r[t]=="function"}function o(r,t,e){var i;for(i=e;i>=0;i--)if(t===r[i])return i;return-1}function v(r,t,e){var i,n;for(i=c(r),n=e;n>=0;n--)if(t===i(r,n))return n;return-1}function g(r,t,e){if(l(r,"lastIndexOf"))return r.lastIndexOf(t,e);if(e<0){if(e+=r.length,e<0)return-1}else e>r.length&&(e=r.length-1);return f(r)?v(r,t,e):o(r,t,e)}u.exports=g
|
|
3
|
+
});var h=s();module.exports=h;
|
|
4
4
|
/** @license Apache-2.0 */
|
|
5
5
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../lib/main.js", "../lib/index.js"],
|
|
4
|
-
"sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar
|
|
5
|
-
"mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,
|
|
6
|
-
"names": ["require_main", "__commonJSMin", "exports", "module", "
|
|
4
|
+
"sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isAccessorArray = require( '@stdlib/assert-is-accessor-array' );\nvar resolveGetter = require( '@stdlib/array-base-resolve-getter' );\n\n\n// FUNCTIONS //\n\n/**\n* Tests whether an object has a specified method.\n*\n* @private\n* @param {Object} obj - input object\n* @param {string} method - method name\n* @returns {boolean} boolean indicating whether an object has a specified method\n*\n* @example\n* var bool = hasMethod( [], 'lastIndexOf' );\n* // returns true\n*\n* @example\n* var bool = hasMethod( [], 'beep' );\n* // returns false\n*/\nfunction hasMethod( obj, method ) {\n\treturn ( typeof obj[ method ] === 'function' );\n}\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* @private\n* @param {Collection} x - input array\n* @param {*} searchElement - search element\n* @param {NonNegativeInteger} fromIndex - starting index (inclusive)\n* @returns {integer} index\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = internal( x, 2, 3 );\n* // returns 1\n*/\nfunction internal( x, searchElement, fromIndex ) {\n\tvar i;\n\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\tif ( searchElement === x[ i ] ) {\n\t\t\treturn i;\n\t\t}\n\t}\n\treturn -1;\n}\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* @private\n* @param {Object} x - input array object\n* @param {*} searchElement - search element\n* @param {NonNegativeInteger} fromIndex - starting index (inclusive)\n* @returns {integer} index\n*\n* @example\n* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' );\n*\n* var x = toAccessorArray( [ 1, 2, 3, 4 ] );\n*\n* var idx = accessors( x, 2, 3 );\n* // returns 1\n*/\nfunction accessors( x, searchElement, fromIndex ) {\n\tvar get;\n\tvar i;\n\n\tget = resolveGetter( x );\n\tfor ( i = fromIndex; i >= 0; i-- ) {\n\t\tif ( searchElement === get( x, i ) ) {\n\t\t\treturn i;\n\t\t}\n\t}\n\treturn -1;\n}\n\n\n// MAIN //\n\n/**\n* Returns the index of the last element which equals a provided search element.\n*\n* ## Notes\n*\n* - If unable to find an element which equals a provided search element, the function returns `-1`.\n*\n* @param {Collection} x - input array\n* @param {*} searchElement - search element\n* @param {integer} fromIndex - starting index (inclusive)\n* @returns {integer} index\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = lastIndexOf( x, 2, 3 );\n* // returns 1\n*\n* @example\n* var Int32Array = require( '@stdlib/array-int32' );\n*\n* var x = new Int32Array( [ 1, 2, 3, 4 ] );\n*\n* var idx = lastIndexOf( x, 2, 3 );\n* // returns 1\n*/\nfunction lastIndexOf( x, searchElement, fromIndex ) {\n\tif ( hasMethod( x, 'lastIndexOf' ) ) {\n\t\treturn x.lastIndexOf( searchElement, fromIndex );\n\t}\n\tif ( fromIndex < 0 ) {\n\t\tfromIndex += x.length;\n\t\tif ( fromIndex < 0 ) {\n\t\t\treturn -1;\n\t\t}\n\t} else if ( fromIndex > x.length ) {\n\t\tfromIndex = x.length - 1;\n\t}\n\tif ( isAccessorArray( x ) ) {\n\t\treturn accessors( x, searchElement, fromIndex );\n\t}\n\treturn internal( x, searchElement, fromIndex );\n}\n\n\n// EXPORTS //\n\nmodule.exports = lastIndexOf;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Return the index of the last element which equals a provided search element.\n*\n* @module @stdlib/array-base-last-index-of\n*\n* @example\n* var lastIndexOf = require( '@stdlib/array-base-last-index-of' );\n*\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = lastIndexOf( x, 2, 3 );\n* // returns 1\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"],
|
|
5
|
+
"mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAkB,QAAS,kCAAmC,EAC9DC,EAAgB,QAAS,mCAAoC,EAqBjE,SAASC,EAAWC,EAAKC,EAAS,CACjC,OAAS,OAAOD,EAAKC,CAAO,GAAM,UACnC,CAiBA,SAASC,EAAUC,EAAGC,EAAeC,EAAY,CAChD,IAAI,EACJ,IAAM,EAAIA,EAAW,GAAK,EAAG,IAC5B,GAAKD,IAAkBD,EAAG,CAAE,EAC3B,OAAO,EAGT,MAAO,EACR,CAmBA,SAASG,EAAWH,EAAGC,EAAeC,EAAY,CACjD,IAAIE,EACAC,EAGJ,IADAD,EAAMT,EAAeK,CAAE,EACjBK,EAAIH,EAAWG,GAAK,EAAGA,IAC5B,GAAKJ,IAAkBG,EAAKJ,EAAGK,CAAE,EAChC,OAAOA,EAGT,MAAO,EACR,CA+BA,SAASC,EAAaN,EAAGC,EAAeC,EAAY,CACnD,GAAKN,EAAWI,EAAG,aAAc,EAChC,OAAOA,EAAE,YAAaC,EAAeC,CAAU,EAEhD,GAAKA,EAAY,GAEhB,GADAA,GAAaF,EAAE,OACVE,EAAY,EAChB,MAAO,QAEGA,EAAYF,EAAE,SACzBE,EAAYF,EAAE,OAAS,GAExB,OAAKN,EAAiBM,CAAE,EAChBG,EAAWH,EAAGC,EAAeC,CAAU,EAExCH,EAAUC,EAAGC,EAAeC,CAAU,CAC9C,CAKAT,EAAO,QAAUa,ICrHjB,IAAIC,EAAO,IAKX,OAAO,QAAUA",
|
|
6
|
+
"names": ["require_main", "__commonJSMin", "exports", "module", "isAccessorArray", "resolveGetter", "hasMethod", "obj", "method", "internal", "x", "searchElement", "fromIndex", "accessors", "get", "i", "lastIndexOf", "main"]
|
|
7
7
|
}
|
package/docs/types/index.d.ts
CHANGED
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
|
|
21
21
|
/// <reference types="@stdlib/types"/>
|
|
22
22
|
|
|
23
|
-
import { Collection,
|
|
23
|
+
import { Collection, AccessorArrayLike } from '@stdlib/types/array';
|
|
24
24
|
|
|
25
25
|
/**
|
|
26
26
|
* Returns the index of the last element which equals a provided search element.
|
|
@@ -34,13 +34,12 @@ import { Collection, Complex64Array, Complex128Array } from '@stdlib/types/array
|
|
|
34
34
|
* @param x - input array
|
|
35
35
|
* @param searchElement - search element
|
|
36
36
|
* @param fromIndex - starting index (inclusive)
|
|
37
|
-
* @param equalNaNs - boolean indicating whether NaNs should be considered equal
|
|
38
37
|
* @returns index
|
|
39
38
|
*
|
|
40
39
|
* @example
|
|
41
40
|
* var x = [ 1, 2, 3, 4 ];
|
|
42
41
|
*
|
|
43
|
-
* var idx = lastIndexOf( x, 2, 3
|
|
42
|
+
* var idx = lastIndexOf( x, 2, 3 );
|
|
44
43
|
* // returns 1
|
|
45
44
|
*
|
|
46
45
|
* @example
|
|
@@ -48,10 +47,10 @@ import { Collection, Complex64Array, Complex128Array } from '@stdlib/types/array
|
|
|
48
47
|
*
|
|
49
48
|
* var x = new Int32Array( [ 1, 2, 3, 4 ] );
|
|
50
49
|
*
|
|
51
|
-
* var idx = lastIndexOf( x, 2, 3
|
|
50
|
+
* var idx = lastIndexOf( x, 2, 3 );
|
|
52
51
|
* // returns 1
|
|
53
52
|
*/
|
|
54
|
-
declare function lastIndexOf( x: Collection |
|
|
53
|
+
declare function lastIndexOf( x: Collection | AccessorArrayLike<unknown>, searchElement: unknown, fromIndex: number ): number;
|
|
55
54
|
|
|
56
55
|
|
|
57
56
|
// EXPORTS //
|
package/lib/index.js
CHANGED
package/lib/main.js
CHANGED
|
@@ -20,8 +20,8 @@
|
|
|
20
20
|
|
|
21
21
|
// MODULES //
|
|
22
22
|
|
|
23
|
-
var
|
|
24
|
-
var
|
|
23
|
+
var isAccessorArray = require( '@stdlib/assert-is-accessor-array' );
|
|
24
|
+
var resolveGetter = require( '@stdlib/array-base-resolve-getter' );
|
|
25
25
|
|
|
26
26
|
|
|
27
27
|
// FUNCTIONS //
|
|
@@ -53,25 +53,16 @@ function hasMethod( obj, method ) {
|
|
|
53
53
|
* @param {Collection} x - input array
|
|
54
54
|
* @param {*} searchElement - search element
|
|
55
55
|
* @param {NonNegativeInteger} fromIndex - starting index (inclusive)
|
|
56
|
-
* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal
|
|
57
56
|
* @returns {integer} index
|
|
58
57
|
*
|
|
59
58
|
* @example
|
|
60
59
|
* var x = [ 1, 2, 3, 4 ];
|
|
61
60
|
*
|
|
62
|
-
* var idx = internal( x, 2, 3
|
|
61
|
+
* var idx = internal( x, 2, 3 );
|
|
63
62
|
* // returns 1
|
|
64
63
|
*/
|
|
65
|
-
function internal( x, searchElement, fromIndex
|
|
64
|
+
function internal( x, searchElement, fromIndex ) {
|
|
66
65
|
var i;
|
|
67
|
-
if ( equalNaNs && isnan( searchElement ) ) {
|
|
68
|
-
for ( i = fromIndex; i >= 0; i-- ) {
|
|
69
|
-
if ( isnan( x[ i ] ) ) {
|
|
70
|
-
return i;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
return -1;
|
|
74
|
-
}
|
|
75
66
|
for ( i = fromIndex; i >= 0; i-- ) {
|
|
76
67
|
if ( searchElement === x[ i ] ) {
|
|
77
68
|
return i;
|
|
@@ -87,36 +78,23 @@ function internal( x, searchElement, fromIndex, equalNaNs ) {
|
|
|
87
78
|
* @param {Object} x - input array object
|
|
88
79
|
* @param {*} searchElement - search element
|
|
89
80
|
* @param {NonNegativeInteger} fromIndex - starting index (inclusive)
|
|
90
|
-
* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal
|
|
91
81
|
* @returns {integer} index
|
|
92
82
|
*
|
|
93
83
|
* @example
|
|
94
84
|
* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' );
|
|
95
|
-
* var arraylike2object = require( '@stdlib/array-base-arraylike2object' );
|
|
96
85
|
*
|
|
97
|
-
* var x =
|
|
86
|
+
* var x = toAccessorArray( [ 1, 2, 3, 4 ] );
|
|
98
87
|
*
|
|
99
|
-
* var idx = accessors( x, 2, 3
|
|
88
|
+
* var idx = accessors( x, 2, 3 );
|
|
100
89
|
* // returns 1
|
|
101
90
|
*/
|
|
102
|
-
function accessors( x, searchElement, fromIndex
|
|
103
|
-
var data;
|
|
91
|
+
function accessors( x, searchElement, fromIndex ) {
|
|
104
92
|
var get;
|
|
105
93
|
var i;
|
|
106
94
|
|
|
107
|
-
|
|
108
|
-
get = x.accessors[ 0 ];
|
|
109
|
-
|
|
110
|
-
if ( equalNaNs && isnan( searchElement ) ) {
|
|
111
|
-
for ( i = fromIndex; i >= 0; i-- ) {
|
|
112
|
-
if ( isnan( get( data, i ) ) ) {
|
|
113
|
-
return i;
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
return -1;
|
|
117
|
-
}
|
|
95
|
+
get = resolveGetter( x );
|
|
118
96
|
for ( i = fromIndex; i >= 0; i-- ) {
|
|
119
|
-
if ( searchElement === get(
|
|
97
|
+
if ( searchElement === get( x, i ) ) {
|
|
120
98
|
return i;
|
|
121
99
|
}
|
|
122
100
|
}
|
|
@@ -136,13 +114,12 @@ function accessors( x, searchElement, fromIndex, equalNaNs ) {
|
|
|
136
114
|
* @param {Collection} x - input array
|
|
137
115
|
* @param {*} searchElement - search element
|
|
138
116
|
* @param {integer} fromIndex - starting index (inclusive)
|
|
139
|
-
* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal
|
|
140
117
|
* @returns {integer} index
|
|
141
118
|
*
|
|
142
119
|
* @example
|
|
143
120
|
* var x = [ 1, 2, 3, 4 ];
|
|
144
121
|
*
|
|
145
|
-
* var idx = lastIndexOf( x, 2, 3
|
|
122
|
+
* var idx = lastIndexOf( x, 2, 3 );
|
|
146
123
|
* // returns 1
|
|
147
124
|
*
|
|
148
125
|
* @example
|
|
@@ -150,12 +127,11 @@ function accessors( x, searchElement, fromIndex, equalNaNs ) {
|
|
|
150
127
|
*
|
|
151
128
|
* var x = new Int32Array( [ 1, 2, 3, 4 ] );
|
|
152
129
|
*
|
|
153
|
-
* var idx = lastIndexOf( x, 2, 3
|
|
130
|
+
* var idx = lastIndexOf( x, 2, 3 );
|
|
154
131
|
* // returns 1
|
|
155
132
|
*/
|
|
156
|
-
function lastIndexOf( x, searchElement, fromIndex
|
|
157
|
-
|
|
158
|
-
if ( hasMethod( x, 'lastIndexOf' ) && equalNaNs === false ) {
|
|
133
|
+
function lastIndexOf( x, searchElement, fromIndex ) {
|
|
134
|
+
if ( hasMethod( x, 'lastIndexOf' ) ) {
|
|
159
135
|
return x.lastIndexOf( searchElement, fromIndex );
|
|
160
136
|
}
|
|
161
137
|
if ( fromIndex < 0 ) {
|
|
@@ -166,11 +142,10 @@ function lastIndexOf( x, searchElement, fromIndex, equalNaNs ) {
|
|
|
166
142
|
} else if ( fromIndex > x.length ) {
|
|
167
143
|
fromIndex = x.length - 1;
|
|
168
144
|
}
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
return accessors( obj, searchElement, fromIndex, equalNaNs );
|
|
145
|
+
if ( isAccessorArray( x ) ) {
|
|
146
|
+
return accessors( x, searchElement, fromIndex );
|
|
172
147
|
}
|
|
173
|
-
return internal( x, searchElement, fromIndex
|
|
148
|
+
return internal( x, searchElement, fromIndex );
|
|
174
149
|
}
|
|
175
150
|
|
|
176
151
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stdlib/array-base-last-index-of",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Return the index of the last element which equals a provided search element.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": {
|
|
@@ -30,8 +30,8 @@
|
|
|
30
30
|
"url": "https://github.com/stdlib-js/stdlib/issues"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@stdlib/array-base-
|
|
34
|
-
"@stdlib/
|
|
33
|
+
"@stdlib/array-base-resolve-getter": "^0.2.2",
|
|
34
|
+
"@stdlib/assert-is-accessor-array": "^0.2.2"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {},
|
|
37
37
|
"engines": {
|