@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 CHANGED
@@ -1 +1 @@
1
- Copyright (c) 2016-2024 The Stdlib Authors.
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, equalNaNs )
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, false );
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, false );
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, false );
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, false );
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 and `equalNaNs` is `false`, the function defers execution to that method and assumes that the method API has the following signature:
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 or if `equalNaNs` is `true`, the function performs a linear scan and returns immediately upon finding a match.
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, false );
141
+ var idx = indexOf( x, 'beep', 0 );
152
142
  // returns 2
153
143
 
154
- idx = indexOf( x, 'bop', 0, false );
144
+ idx = indexOf( x, 'bop', 0 );
155
145
  // returns -1
156
146
 
157
- idx = indexOf( x, 'foo', 1, false );
147
+ idx = indexOf( x, 'foo', 1 );
158
148
  // returns 4
159
149
 
160
- idx = indexOf( x, 'foo', -4, false );
150
+ idx = indexOf( x, 'foo', -4 );
161
151
  // returns 4
162
152
 
163
- idx = indexOf( x, 'foo', 5, false );
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 &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
203
+ Copyright &copy; 2016-2026. The Stdlib [Authors][stdlib-authors].
214
204
 
215
205
  </section>
216
206
 
@@ -223,8 +213,8 @@ Copyright &copy; 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.2.2
227
- [test-url]: https://github.com/stdlib-js/array-base-index-of/actions/workflows/test.yml?query=branch:v0.2.2
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 &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
236
226
 
237
227
  -->
238
228
 
239
- [chat-image]: https://img.shields.io/gitter/room/stdlib-js/stdlib.svg
240
- [chat-url]: https://app.gitter.im/#/room/#stdlib-js_stdlib:gitter.im
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 s=function(t,i){return function(){return i||t((i={exports:{}}).exports,i),i.exports}};var c=s(function(j,o){
2
- var v=require('@stdlib/array-base-arraylike2object/dist'),f=require('@stdlib/math-base-assert-is-nan/dist');function g(t,i){return typeof t[i]=="function"}function h(t,i,n,e){var r;if(e&&f(i)){for(r=n;r<t.length;r++)if(f(t[r]))return r;return-1}for(r=n;r<t.length;r++)if(i===t[r])return r;return-1}function l(t,i,n,e){var r,a,u;if(r=t.data,a=t.accessors[0],e&&f(i)){for(u=n;u<r.length;u++)if(f(a(r,u)))return u;return-1}for(u=n;u<r.length;u++)if(i===a(r,u))return u;return-1}function p(t,i,n,e){var r;return g(t,"indexOf")&&e===!1?t.indexOf(i,n):(n<0&&(n+=t.length,n<0&&(n=0)),r=v(t),r.accessorProtocol?l(r,i,n,e):h(t,i,n,e))}o.exports=p
3
- });var O=c();module.exports=O;
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 arraylike2object = require( '@stdlib/array-base-arraylike2object' );\nvar isnan = require( '@stdlib/math-base-assert-is-nan' );\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* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = internal( x, 2, 0, false );\n* // returns 1\n*/\nfunction internal( x, searchElement, fromIndex, equalNaNs ) {\n\tvar i;\n\tif ( equalNaNs && isnan( searchElement ) ) {\n\t\tfor ( i = fromIndex; i < x.length; i++ ) {\n\t\t\tif ( isnan( x[ i ] ) ) {\n\t\t\t\treturn i;\n\t\t\t}\n\t\t}\n\t\treturn -1;\n\t}\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* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' );\n* var arraylike2object = require( '@stdlib/array-base-arraylike2object' );\n*\n* var x = arraylike2object( toAccessorArray( [ 1, 2, 3, 4 ] ) );\n*\n* var idx = accessors( x, 2, 0, false );\n* // returns 1\n*/\nfunction accessors( x, searchElement, fromIndex, equalNaNs ) {\n\tvar data;\n\tvar get;\n\tvar i;\n\n\tdata = x.data;\n\tget = x.accessors[ 0 ];\n\n\tif ( equalNaNs && isnan( searchElement ) ) {\n\t\tfor ( i = fromIndex; i < data.length; i++ ) {\n\t\t\tif ( isnan( get( data, i ) ) ) {\n\t\t\t\treturn i;\n\t\t\t}\n\t\t}\n\t\treturn -1;\n\t}\n\tfor ( i = fromIndex; i < data.length; i++ ) {\n\t\tif ( searchElement === get( data, 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* @param {boolean} equalNaNs - boolean indicating whether NaNs should be considered equal\n* @returns {integer} index\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = indexOf( x, 2, 0, false );\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, false );\n* // returns 1\n*/\nfunction indexOf( x, searchElement, fromIndex, equalNaNs ) {\n\tvar obj;\n\tif ( hasMethod( x, 'indexOf' ) && equalNaNs === false ) {\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\tobj = arraylike2object( x );\n\tif ( obj.accessorProtocol ) {\n\t\treturn accessors( obj, searchElement, fromIndex, equalNaNs );\n\t}\n\treturn internal( x, searchElement, fromIndex, equalNaNs );\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, false );\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,EAAmB,QAAS,qCAAsC,EAClEC,EAAQ,QAAS,iCAAkC,EAqBvD,SAASC,EAAWC,EAAKC,EAAS,CACjC,OAAS,OAAOD,EAAKC,CAAO,GAAM,UACnC,CAkBA,SAASC,EAAUC,EAAGC,EAAeC,EAAWC,EAAY,CAC3D,IAAIC,EACJ,GAAKD,GAAaR,EAAOM,CAAc,EAAI,CAC1C,IAAMG,EAAIF,EAAWE,EAAIJ,EAAE,OAAQI,IAClC,GAAKT,EAAOK,EAAGI,CAAE,CAAE,EAClB,OAAOA,EAGT,MAAO,EACR,CACA,IAAMA,EAAIF,EAAWE,EAAIJ,EAAE,OAAQI,IAClC,GAAKH,IAAkBD,EAAGI,CAAE,EAC3B,OAAOA,EAGT,MAAO,EACR,CAqBA,SAASC,EAAWL,EAAGC,EAAeC,EAAWC,EAAY,CAC5D,IAAIG,EACAC,EACAH,EAKJ,GAHAE,EAAON,EAAE,KACTO,EAAMP,EAAE,UAAW,CAAE,EAEhBG,GAAaR,EAAOM,CAAc,EAAI,CAC1C,IAAMG,EAAIF,EAAWE,EAAIE,EAAK,OAAQF,IACrC,GAAKT,EAAOY,EAAKD,EAAMF,CAAE,CAAE,EAC1B,OAAOA,EAGT,MAAO,EACR,CACA,IAAMA,EAAIF,EAAWE,EAAIE,EAAK,OAAQF,IACrC,GAAKH,IAAkBM,EAAKD,EAAMF,CAAE,EACnC,OAAOA,EAGT,MAAO,EACR,CAgCA,SAASI,EAASR,EAAGC,EAAeC,EAAWC,EAAY,CAC1D,IAAIN,EACJ,OAAKD,EAAWI,EAAG,SAAU,GAAKG,IAAc,GACxCH,EAAE,QAASC,EAAeC,CAAU,GAEvCA,EAAY,IAChBA,GAAaF,EAAE,OACVE,EAAY,IAChBA,EAAY,IAGdL,EAAMH,EAAkBM,CAAE,EACrBH,EAAI,iBACDQ,EAAWR,EAAKI,EAAeC,EAAWC,CAAU,EAErDJ,EAAUC,EAAGC,EAAeC,EAAWC,CAAU,EACzD,CAKAV,EAAO,QAAUe,IC5IjB,IAAIC,EAAO,IAKX,OAAO,QAAUA",
6
- "names": ["require_main", "__commonJSMin", "exports", "module", "arraylike2object", "isnan", "hasMethod", "obj", "method", "internal", "x", "searchElement", "fromIndex", "equalNaNs", "i", "accessors", "data", "get", "indexOf", "main"]
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
  }
@@ -20,7 +20,7 @@
20
20
 
21
21
  /// <reference types="@stdlib/types"/>
22
22
 
23
- import { Collection, Complex64Array, Complex128Array } from '@stdlib/types/array';
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, false );
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, false );
49
+ * var idx = indexOf( x, 2, 0 );
51
50
  * // returns 1
52
51
  */
53
- declare function indexOf( x: Collection | Complex64Array | Complex128Array, searchElement: any, fromIndex: number, equalNaNs: boolean ): number;
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
@@ -28,7 +28,7 @@
28
28
  *
29
29
  * var x = [ 1, 2, 3, 4 ];
30
30
  *
31
- * var idx = indexOf( x, 2, 0, false );
31
+ * var idx = indexOf( x, 2, 0 );
32
32
  * // returns 1
33
33
  */
34
34
 
package/lib/main.js CHANGED
@@ -20,8 +20,8 @@
20
20
 
21
21
  // MODULES //
22
22
 
23
- var arraylike2object = require( '@stdlib/array-base-arraylike2object' );
24
- var isnan = require( '@stdlib/math-base-assert-is-nan' );
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, false );
61
+ * var idx = internal( x, 2, 0 );
63
62
  * // returns 1
64
63
  */
65
- function internal( x, searchElement, fromIndex, equalNaNs ) {
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 = arraylike2object( toAccessorArray( [ 1, 2, 3, 4 ] ) );
86
+ * var x = toAccessorArray( [ 1, 2, 3, 4 ] );
98
87
  *
99
- * var idx = accessors( x, 2, 0, false );
88
+ * var idx = accessors( x, 2, 0 );
100
89
  * // returns 1
101
90
  */
102
- function accessors( x, searchElement, fromIndex, equalNaNs ) {
103
- var data;
91
+ function accessors( x, searchElement, fromIndex ) {
104
92
  var get;
105
93
  var i;
106
94
 
107
- data = x.data;
108
- get = x.accessors[ 0 ];
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, false );
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, false );
130
+ * var idx = indexOf( x, 2, 0 );
154
131
  * // returns 1
155
132
  */
156
- function indexOf( x, searchElement, fromIndex, equalNaNs ) {
157
- var obj;
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
- obj = arraylike2object( x );
168
- if ( obj.accessorProtocol ) {
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, equalNaNs );
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.2.2",
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-arraylike2object": "^0.2.1",
34
- "@stdlib/math-base-assert-is-nan": "^0.2.2"
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": {