@stdlib/array-base-index-of 0.2.2 → 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 +19 -29
- 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 +17 -42
- 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-index-of
|
|
|
63
63
|
var indexOf = require( '@stdlib/array-base-index-of' );
|
|
64
64
|
```
|
|
65
65
|
|
|
66
|
-
#### indexOf( x, searchElement, fromIndex
|
|
66
|
+
#### indexOf( x, searchElement, fromIndex )
|
|
67
67
|
|
|
68
68
|
Returns the index of the first 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 = indexOf( x, 3, 0
|
|
73
|
+
var idx = indexOf( x, 3, 0 );
|
|
74
74
|
// returns 2
|
|
75
75
|
```
|
|
76
76
|
|
|
@@ -79,7 +79,7 @@ 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 = indexOf( x, 7, 0
|
|
82
|
+
var idx = indexOf( x, 7, 0 );
|
|
83
83
|
// returns -1
|
|
84
84
|
```
|
|
85
85
|
|
|
@@ -88,7 +88,7 @@ To begin searching from specific index, provide a non-zero `fromIndex` argument.
|
|
|
88
88
|
```javascript
|
|
89
89
|
var x = [ 1, 1, 2, 1, 2, 3, 3 ];
|
|
90
90
|
|
|
91
|
-
var idx = indexOf( x, 2, 3
|
|
91
|
+
var idx = indexOf( x, 2, 3 );
|
|
92
92
|
// returns 4
|
|
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 = indexOf( x, 2, -4
|
|
100
|
+
var idx = indexOf( x, 2, -4 );
|
|
101
101
|
// returns 4
|
|
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 first 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 = indexOf( x, NaN, 0, false );
|
|
110
|
-
// returns -1
|
|
111
|
-
|
|
112
|
-
idx = indexOf( x, NaN, 0, true );
|
|
113
|
-
// returns 3
|
|
114
|
-
```
|
|
115
|
-
|
|
116
104
|
</section>
|
|
117
105
|
|
|
118
106
|
<!-- /.usage -->
|
|
@@ -123,13 +111,15 @@ idx = indexOf( x, NaN, 0, true );
|
|
|
123
111
|
|
|
124
112
|
## Notes
|
|
125
113
|
|
|
126
|
-
- If provided an array-like object having an `indexOf` method
|
|
114
|
+
- If provided an array-like object having an `indexOf` method, the function defers execution to that method and assumes that the method API has the following signature:
|
|
127
115
|
|
|
128
116
|
```text
|
|
129
117
|
x.indexOf( searchElement, fromIndex )
|
|
130
118
|
```
|
|
131
119
|
|
|
132
|
-
- If provided an array-like object without an `indexOf` method
|
|
120
|
+
- If provided an array-like object without an `indexOf` method, the function performs a linear scan and returns immediately upon finding a match.
|
|
121
|
+
|
|
122
|
+
- 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.
|
|
133
123
|
|
|
134
124
|
</section>
|
|
135
125
|
|
|
@@ -148,19 +138,19 @@ var indexOf = require( '@stdlib/array-base-index-of' );
|
|
|
148
138
|
|
|
149
139
|
var x = [ 'foo', 'bar', 'beep', 'boop', 'foo', 'bar' ];
|
|
150
140
|
|
|
151
|
-
var idx = indexOf( x, 'beep', 0
|
|
141
|
+
var idx = indexOf( x, 'beep', 0 );
|
|
152
142
|
// returns 2
|
|
153
143
|
|
|
154
|
-
idx = indexOf( x, 'bop', 0
|
|
144
|
+
idx = indexOf( x, 'bop', 0 );
|
|
155
145
|
// returns -1
|
|
156
146
|
|
|
157
|
-
idx = indexOf( x, 'foo', 1
|
|
147
|
+
idx = indexOf( x, 'foo', 1 );
|
|
158
148
|
// returns 4
|
|
159
149
|
|
|
160
|
-
idx = indexOf( x, 'foo', -4
|
|
150
|
+
idx = indexOf( x, 'foo', -4 );
|
|
161
151
|
// returns 4
|
|
162
152
|
|
|
163
|
-
idx = indexOf( x, 'foo', 5
|
|
153
|
+
idx = indexOf( x, 'foo', 5 );
|
|
164
154
|
// returns -1
|
|
165
155
|
```
|
|
166
156
|
|
|
@@ -210,7 +200,7 @@ See [LICENSE][stdlib-license].
|
|
|
210
200
|
|
|
211
201
|
## Copyright
|
|
212
202
|
|
|
213
|
-
Copyright © 2016-
|
|
203
|
+
Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors].
|
|
214
204
|
|
|
215
205
|
</section>
|
|
216
206
|
|
|
@@ -223,8 +213,8 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors].
|
|
|
223
213
|
[npm-image]: http://img.shields.io/npm/v/@stdlib/array-base-index-of.svg
|
|
224
214
|
[npm-url]: https://npmjs.org/package/@stdlib/array-base-index-of
|
|
225
215
|
|
|
226
|
-
[test-image]: https://github.com/stdlib-js/array-base-index-of/actions/workflows/test.yml/badge.svg?branch=v0.
|
|
227
|
-
[test-url]: https://github.com/stdlib-js/array-base-index-of/actions/workflows/test.yml?query=branch:v0.
|
|
216
|
+
[test-image]: https://github.com/stdlib-js/array-base-index-of/actions/workflows/test.yml/badge.svg?branch=v0.3.0
|
|
217
|
+
[test-url]: https://github.com/stdlib-js/array-base-index-of/actions/workflows/test.yml?query=branch:v0.3.0
|
|
228
218
|
|
|
229
219
|
[coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/array-base-index-of/main.svg
|
|
230
220
|
[coverage-url]: https://codecov.io/github/stdlib-js/array-base-index-of?branch=main
|
|
@@ -236,8 +226,8 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors].
|
|
|
236
226
|
|
|
237
227
|
-->
|
|
238
228
|
|
|
239
|
-
[chat-image]: https://img.shields.io/
|
|
240
|
-
[chat-url]: https://
|
|
229
|
+
[chat-image]: https://img.shields.io/badge/zulip-join_chat-brightgreen.svg
|
|
230
|
+
[chat-url]: https://stdlib.zulipchat.com
|
|
241
231
|
|
|
242
232
|
[stdlib]: https://github.com/stdlib-js/stdlib
|
|
243
233
|
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
"use strict";var
|
|
2
|
-
var
|
|
3
|
-
});var
|
|
1
|
+
"use strict";var f=function(r,t){return function(){return t||r((t={exports:{}}).exports,t),t.exports}};var s=f(function(q,u){
|
|
2
|
+
var a=require('@stdlib/assert-is-accessor-array/dist'),c=require('@stdlib/array-base-resolve-getter/dist');function o(r,t){return typeof r[t]=="function"}function v(r,t,i){var e;for(e=i;e<r.length;e++)if(t===r[e])return e;return-1}function g(r,t,i){var e,n;for(e=c(r),n=i;n<r.length;n++)if(t===e(r,n))return n;return-1}function h(r,t,i){return o(r,"indexOf")?r.indexOf(t,i):(i<0&&(i+=r.length,i<0&&(i=0)),a(r)?g(r,t,i):v(r,t,i))}u.exports=h
|
|
3
|
+
});var l=s();module.exports=l;
|
|
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( [], 'indexOf' );\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 first 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, 0 );\n* // returns 1\n*/\nfunction internal( x, searchElement, fromIndex ) {\n\tvar i;\n\tfor ( i = fromIndex; i < x.length; 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 first 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, 0 );\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 < x.length; 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 first 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 = indexOf( x, 2, 0 );\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 = indexOf( x, 2, 0 );\n* // returns 1\n*/\nfunction indexOf( x, searchElement, fromIndex ) {\n\tif ( hasMethod( x, 'indexOf' ) ) {\n\t\treturn x.indexOf( searchElement, fromIndex );\n\t}\n\tif ( fromIndex < 0 ) {\n\t\tfromIndex += x.length;\n\t\tif ( fromIndex < 0 ) {\n\t\t\tfromIndex = 0;\n\t\t}\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 = indexOf;\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 first element which equals a provided search element.\n*\n* @module @stdlib/array-base-index-of\n*\n* @example\n* var indexOf = require( '@stdlib/array-base-index-of' );\n*\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = indexOf( x, 2, 0 );\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,IAAIC,EACJ,IAAMA,EAAID,EAAWC,EAAIH,EAAE,OAAQG,IAClC,GAAKF,IAAkBD,EAAGG,CAAE,EAC3B,OAAOA,EAGT,MAAO,EACR,CAmBA,SAASC,EAAWJ,EAAGC,EAAeC,EAAY,CACjD,IAAIG,EACAF,EAGJ,IADAE,EAAMV,EAAeK,CAAE,EACjBG,EAAID,EAAWC,EAAIH,EAAE,OAAQG,IAClC,GAAKF,IAAkBI,EAAKL,EAAGG,CAAE,EAChC,OAAOA,EAGT,MAAO,EACR,CA+BA,SAASG,EAASN,EAAGC,EAAeC,EAAY,CAC/C,OAAKN,EAAWI,EAAG,SAAU,EACrBA,EAAE,QAASC,EAAeC,CAAU,GAEvCA,EAAY,IAChBA,GAAaF,EAAE,OACVE,EAAY,IAChBA,EAAY,IAGTR,EAAiBM,CAAE,EAChBI,EAAWJ,EAAGC,EAAeC,CAAU,EAExCH,EAAUC,EAAGC,EAAeC,CAAU,EAC9C,CAKAT,EAAO,QAAUa,ICnHjB,IAAIC,EAAO,IAKX,OAAO,QAAUA",
|
|
6
|
+
"names": ["require_main", "__commonJSMin", "exports", "module", "isAccessorArray", "resolveGetter", "hasMethod", "obj", "method", "internal", "x", "searchElement", "fromIndex", "i", "accessors", "get", "indexOf", "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 first element which equals a provided search element.
|
|
@@ -33,13 +33,12 @@ import { Collection, Complex64Array, Complex128Array } from '@stdlib/types/array
|
|
|
33
33
|
* @param x - input array
|
|
34
34
|
* @param searchElement - search element
|
|
35
35
|
* @param fromIndex - starting index (inclusive)
|
|
36
|
-
* @param equalNaNs - boolean indicating whether NaNs should be considered equal
|
|
37
36
|
* @returns index
|
|
38
37
|
*
|
|
39
38
|
* @example
|
|
40
39
|
* var x = [ 1, 2, 3, 4 ];
|
|
41
40
|
*
|
|
42
|
-
* var idx = indexOf( x, 2, 0
|
|
41
|
+
* var idx = indexOf( x, 2, 0 );
|
|
43
42
|
* // returns 1
|
|
44
43
|
*
|
|
45
44
|
* @example
|
|
@@ -47,10 +46,10 @@ import { Collection, Complex64Array, Complex128Array } from '@stdlib/types/array
|
|
|
47
46
|
*
|
|
48
47
|
* var x = new Int32Array( [ 1, 2, 3, 4 ] );
|
|
49
48
|
*
|
|
50
|
-
* var idx = indexOf( x, 2, 0
|
|
49
|
+
* var idx = indexOf( x, 2, 0 );
|
|
51
50
|
* // returns 1
|
|
52
51
|
*/
|
|
53
|
-
declare function indexOf( x: Collection |
|
|
52
|
+
declare function indexOf( x: Collection | AccessorArrayLike<unknown>, searchElement: unknown, fromIndex: number ): number;
|
|
54
53
|
|
|
55
54
|
|
|
56
55
|
// 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, 0
|
|
61
|
+
* var idx = internal( x, 2, 0 );
|
|
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 < x.length; i++ ) {
|
|
69
|
-
if ( isnan( x[ i ] ) ) {
|
|
70
|
-
return i;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
return -1;
|
|
74
|
-
}
|
|
75
66
|
for ( i = fromIndex; i < x.length; 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, 0
|
|
88
|
+
* var idx = accessors( x, 2, 0 );
|
|
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
|
-
|
|
109
|
-
|
|
110
|
-
if ( equalNaNs && isnan( searchElement ) ) {
|
|
111
|
-
for ( i = fromIndex; i < data.length; i++ ) {
|
|
112
|
-
if ( isnan( get( data, i ) ) ) {
|
|
113
|
-
return i;
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
return -1;
|
|
117
|
-
}
|
|
118
|
-
for ( i = fromIndex; i < data.length; i++ ) {
|
|
119
|
-
if ( searchElement === get( data, i ) ) {
|
|
95
|
+
get = resolveGetter( x );
|
|
96
|
+
for ( i = fromIndex; i < x.length; i++ ) {
|
|
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 = indexOf( x, 2, 0
|
|
122
|
+
* var idx = indexOf( x, 2, 0 );
|
|
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 = indexOf( x, 2, 0
|
|
130
|
+
* var idx = indexOf( x, 2, 0 );
|
|
154
131
|
* // returns 1
|
|
155
132
|
*/
|
|
156
|
-
function indexOf( x, searchElement, fromIndex
|
|
157
|
-
|
|
158
|
-
if ( hasMethod( x, 'indexOf' ) && equalNaNs === false ) {
|
|
133
|
+
function indexOf( x, searchElement, fromIndex ) {
|
|
134
|
+
if ( hasMethod( x, 'indexOf' ) ) {
|
|
159
135
|
return x.indexOf( searchElement, fromIndex );
|
|
160
136
|
}
|
|
161
137
|
if ( fromIndex < 0 ) {
|
|
@@ -164,11 +140,10 @@ function indexOf( x, searchElement, fromIndex, equalNaNs ) {
|
|
|
164
140
|
fromIndex = 0;
|
|
165
141
|
}
|
|
166
142
|
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
return accessors( obj, searchElement, fromIndex, equalNaNs );
|
|
143
|
+
if ( isAccessorArray( x ) ) {
|
|
144
|
+
return accessors( x, searchElement, fromIndex );
|
|
170
145
|
}
|
|
171
|
-
return internal( x, searchElement, fromIndex
|
|
146
|
+
return internal( x, searchElement, fromIndex );
|
|
172
147
|
}
|
|
173
148
|
|
|
174
149
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stdlib/array-base-index-of",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Return the index of the first 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": {
|