@stdlib/array-base-index-of-same-value 0.1.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/LICENSE +177 -0
- package/NOTICE +1 -0
- package/README.md +246 -0
- package/SECURITY.md +5 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +7 -0
- package/docs/types/index.d.ts +61 -0
- package/lib/index.js +42 -0
- package/lib/main.js +219 -0
- package/package.json +80 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
package/NOTICE
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Copyright (c) 2016-2026 The Stdlib Authors.
|
package/README.md
ADDED
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
|
|
3
|
+
@license Apache-2.0
|
|
4
|
+
|
|
5
|
+
Copyright (c) 2025 The Stdlib Authors.
|
|
6
|
+
|
|
7
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
+
you may not use this file except in compliance with the License.
|
|
9
|
+
You may obtain a copy of the License at
|
|
10
|
+
|
|
11
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
|
|
13
|
+
Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
See the License for the specific language governing permissions and
|
|
17
|
+
limitations under the License.
|
|
18
|
+
|
|
19
|
+
-->
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
<details>
|
|
23
|
+
<summary>
|
|
24
|
+
About stdlib...
|
|
25
|
+
</summary>
|
|
26
|
+
<p>We believe in a future in which the web is a preferred environment for numerical computation. To help realize this future, we've built stdlib. stdlib is a standard library, with an emphasis on numerical and scientific computation, written in JavaScript (and C) for execution in browsers and in Node.js.</p>
|
|
27
|
+
<p>The library is fully decomposable, being architected in such a way that you can swap out and mix and match APIs and functionality to cater to your exact preferences and use cases.</p>
|
|
28
|
+
<p>When you use stdlib, you can be absolutely certain that you are using the most thorough, rigorous, well-written, studied, documented, tested, measured, and high-quality code out there.</p>
|
|
29
|
+
<p>To join us in bringing numerical computing to the web, get started by checking us out on <a href="https://github.com/stdlib-js/stdlib">GitHub</a>, and please consider <a href="https://opencollective.com/stdlib">financially supporting stdlib</a>. We greatly appreciate your continued support!</p>
|
|
30
|
+
</details>
|
|
31
|
+
|
|
32
|
+
# indexOfSameValue
|
|
33
|
+
|
|
34
|
+
[![NPM version][npm-image]][npm-url] [![Build Status][test-image]][test-url] [![Coverage Status][coverage-image]][coverage-url] <!-- [![dependencies][dependencies-image]][dependencies-url] -->
|
|
35
|
+
|
|
36
|
+
> Return the index of the first element which equals a provided search element according to the [SameValue Algorithm][@stdlib/assert/is-same-value].
|
|
37
|
+
|
|
38
|
+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
|
|
39
|
+
|
|
40
|
+
<section class="intro">
|
|
41
|
+
|
|
42
|
+
</section>
|
|
43
|
+
|
|
44
|
+
<!-- /.intro -->
|
|
45
|
+
|
|
46
|
+
<!-- Package usage documentation. -->
|
|
47
|
+
|
|
48
|
+
<section class="installation">
|
|
49
|
+
|
|
50
|
+
## Installation
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
npm install @stdlib/array-base-index-of-same-value
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
</section>
|
|
57
|
+
|
|
58
|
+
<section class="usage">
|
|
59
|
+
|
|
60
|
+
## Usage
|
|
61
|
+
|
|
62
|
+
```javascript
|
|
63
|
+
var indexOfSameValue = require( '@stdlib/array-base-index-of-same-value' );
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
#### indexOfSameValue( x, searchElement, fromIndex )
|
|
67
|
+
|
|
68
|
+
Returns the index of the first element which equals a provided search element according to the [SameValue Algorithm][@stdlib/assert/is-same-value].
|
|
69
|
+
|
|
70
|
+
```javascript
|
|
71
|
+
var x = [ 1, 2, 3, 4, 5, 6 ];
|
|
72
|
+
|
|
73
|
+
var idx = indexOfSameValue( x, 3, 0 );
|
|
74
|
+
// returns 2
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
If the function is unable to find an element which equals a provided search element, the function returns `-1`.
|
|
78
|
+
|
|
79
|
+
```javascript
|
|
80
|
+
var x = [ 1, 2, 3, 4, 5, 6 ];
|
|
81
|
+
|
|
82
|
+
var idx = indexOfSameValue( x, 7, 0 );
|
|
83
|
+
// returns -1
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
To begin searching from specific index, provide a non-zero `fromIndex` argument.
|
|
87
|
+
|
|
88
|
+
```javascript
|
|
89
|
+
var x = [ 1, 1, 2, 1, 2, 3, 3 ];
|
|
90
|
+
|
|
91
|
+
var idx = indexOfSameValue( x, 2, 3 );
|
|
92
|
+
// returns 4
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
If `fromIndex` is less than zero, the starting index is resolved relative to the last array element, with the last array element corresponding to `fromIndex = -1`.
|
|
96
|
+
|
|
97
|
+
```javascript
|
|
98
|
+
var x = [ 1, 1, 2, 1, 2, 3, 3 ];
|
|
99
|
+
|
|
100
|
+
var idx = indexOfSameValue( x, 2, -4 );
|
|
101
|
+
// returns 4
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
</section>
|
|
105
|
+
|
|
106
|
+
<!-- /.usage -->
|
|
107
|
+
|
|
108
|
+
<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
|
|
109
|
+
|
|
110
|
+
<section class="notes">
|
|
111
|
+
|
|
112
|
+
## Notes
|
|
113
|
+
|
|
114
|
+
- The function performs a linear scan and returns immediately upon finding a match.
|
|
115
|
+
- When searching for a search element, the function checks for equality using the [SameValue Algorithm][@stdlib/assert/is-same-value] as specified in ECMAScript 5. As a consequence, `NaN` values are considered equal, and `-0` and `+0` are considered distinct.
|
|
116
|
+
|
|
117
|
+
</section>
|
|
118
|
+
|
|
119
|
+
<!-- /.notes -->
|
|
120
|
+
|
|
121
|
+
<!-- Package usage examples. -->
|
|
122
|
+
|
|
123
|
+
<section class="examples">
|
|
124
|
+
|
|
125
|
+
## Examples
|
|
126
|
+
|
|
127
|
+
<!-- eslint no-undef: "error" -->
|
|
128
|
+
|
|
129
|
+
```javascript
|
|
130
|
+
var indexOfSameValue = require( '@stdlib/array-base-index-of-same-value' );
|
|
131
|
+
|
|
132
|
+
var x = [ 'foo', 'bar', 'beep', 'boop', 'foo', 'bar' ];
|
|
133
|
+
|
|
134
|
+
var idx = indexOfSameValue( x, 'beep', 0 );
|
|
135
|
+
// returns 2
|
|
136
|
+
|
|
137
|
+
idx = indexOfSameValue( x, 'bop', 0 );
|
|
138
|
+
// returns -1
|
|
139
|
+
|
|
140
|
+
idx = indexOfSameValue( x, 'foo', 1 );
|
|
141
|
+
// returns 4
|
|
142
|
+
|
|
143
|
+
idx = indexOfSameValue( x, 'foo', -4 );
|
|
144
|
+
// returns 4
|
|
145
|
+
|
|
146
|
+
idx = indexOfSameValue( x, 'foo', 5 );
|
|
147
|
+
// returns -1
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
</section>
|
|
151
|
+
|
|
152
|
+
<!-- /.examples -->
|
|
153
|
+
|
|
154
|
+
<!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
|
|
155
|
+
|
|
156
|
+
<section class="references">
|
|
157
|
+
|
|
158
|
+
</section>
|
|
159
|
+
|
|
160
|
+
<!-- /.references -->
|
|
161
|
+
|
|
162
|
+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
|
|
163
|
+
|
|
164
|
+
<section class="related">
|
|
165
|
+
|
|
166
|
+
</section>
|
|
167
|
+
|
|
168
|
+
<!-- /.related -->
|
|
169
|
+
|
|
170
|
+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
<section class="main-repo" >
|
|
174
|
+
|
|
175
|
+
* * *
|
|
176
|
+
|
|
177
|
+
## Notice
|
|
178
|
+
|
|
179
|
+
This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more.
|
|
180
|
+
|
|
181
|
+
For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib].
|
|
182
|
+
|
|
183
|
+
#### Community
|
|
184
|
+
|
|
185
|
+
[![Chat][chat-image]][chat-url]
|
|
186
|
+
|
|
187
|
+
---
|
|
188
|
+
|
|
189
|
+
## License
|
|
190
|
+
|
|
191
|
+
See [LICENSE][stdlib-license].
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
## Copyright
|
|
195
|
+
|
|
196
|
+
Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors].
|
|
197
|
+
|
|
198
|
+
</section>
|
|
199
|
+
|
|
200
|
+
<!-- /.stdlib -->
|
|
201
|
+
|
|
202
|
+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
|
|
203
|
+
|
|
204
|
+
<section class="links">
|
|
205
|
+
|
|
206
|
+
[npm-image]: http://img.shields.io/npm/v/@stdlib/array-base-index-of-same-value.svg
|
|
207
|
+
[npm-url]: https://npmjs.org/package/@stdlib/array-base-index-of-same-value
|
|
208
|
+
|
|
209
|
+
[test-image]: https://github.com/stdlib-js/array-base-index-of-same-value/actions/workflows/test.yml/badge.svg?branch=v0.1.0
|
|
210
|
+
[test-url]: https://github.com/stdlib-js/array-base-index-of-same-value/actions/workflows/test.yml?query=branch:v0.1.0
|
|
211
|
+
|
|
212
|
+
[coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/array-base-index-of-same-value/main.svg
|
|
213
|
+
[coverage-url]: https://codecov.io/github/stdlib-js/array-base-index-of-same-value?branch=main
|
|
214
|
+
|
|
215
|
+
<!--
|
|
216
|
+
|
|
217
|
+
[dependencies-image]: https://img.shields.io/david/stdlib-js/array-base-index-of-same-value.svg
|
|
218
|
+
[dependencies-url]: https://david-dm.org/stdlib-js/array-base-index-of-same-value/main
|
|
219
|
+
|
|
220
|
+
-->
|
|
221
|
+
|
|
222
|
+
[chat-image]: https://img.shields.io/badge/zulip-join_chat-brightgreen.svg
|
|
223
|
+
[chat-url]: https://stdlib.zulipchat.com
|
|
224
|
+
|
|
225
|
+
[stdlib]: https://github.com/stdlib-js/stdlib
|
|
226
|
+
|
|
227
|
+
[stdlib-authors]: https://github.com/stdlib-js/stdlib/graphs/contributors
|
|
228
|
+
|
|
229
|
+
[umd]: https://github.com/umdjs/umd
|
|
230
|
+
[es-module]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules
|
|
231
|
+
|
|
232
|
+
[deno-url]: https://github.com/stdlib-js/array-base-index-of-same-value/tree/deno
|
|
233
|
+
[deno-readme]: https://github.com/stdlib-js/array-base-index-of-same-value/blob/deno/README.md
|
|
234
|
+
[umd-url]: https://github.com/stdlib-js/array-base-index-of-same-value/tree/umd
|
|
235
|
+
[umd-readme]: https://github.com/stdlib-js/array-base-index-of-same-value/blob/umd/README.md
|
|
236
|
+
[esm-url]: https://github.com/stdlib-js/array-base-index-of-same-value/tree/esm
|
|
237
|
+
[esm-readme]: https://github.com/stdlib-js/array-base-index-of-same-value/blob/esm/README.md
|
|
238
|
+
[branches-url]: https://github.com/stdlib-js/array-base-index-of-same-value/blob/main/branches.md
|
|
239
|
+
|
|
240
|
+
[stdlib-license]: https://raw.githubusercontent.com/stdlib-js/array-base-index-of-same-value/main/LICENSE
|
|
241
|
+
|
|
242
|
+
[@stdlib/assert/is-same-value]: https://www.npmjs.com/package/@stdlib/assert-is-same-value
|
|
243
|
+
|
|
244
|
+
</section>
|
|
245
|
+
|
|
246
|
+
<!-- /.links -->
|
package/SECURITY.md
ADDED
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";var s=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var f=s(function(P,o){
|
|
2
|
+
var q=require('@stdlib/assert-is-accessor-array/dist'),l=require('@stdlib/assert-is-complex-like/dist'),p=require('@stdlib/assert-is-boolean/dist').isPrimitive,g=require('@stdlib/strided-base-reinterpret-complex/dist'),c=require('@stdlib/strided-base-reinterpret-boolean/dist'),y=require('@stdlib/array-base-assert-is-complex-typed-array/dist'),A=require('@stdlib/array-base-assert-is-booleanarray/dist'),B=require('@stdlib/array-base-resolve-getter/dist'),n=require('@stdlib/assert-is-same-value/dist'),w=require('@stdlib/complex-float64-real/dist'),C=require('@stdlib/complex-float64-imag/dist');function S(r,e,u){var i;for(i=u;i<r.length;i++)if(n(e,r[i]))return i;return-1}function V(r,e,u){var i,t;for(i=B(r),t=u;t<r.length;t++)if(n(e,i(r,t)))return t;return-1}function b(r,e,u){var i,t,a,v;if(!l(e))return-1;for(i=g(r,0),t=w(e),a=C(e),v=u*2;v<i.length;v+=2)if(n(i[v],t)&&n(i[v+1],a))return v/2;return-1}function k(r,e,u){var i,t,a;if(!p(e))return-1;for(i=c(r,0),t=e?1:0,a=u;a<i.length;a++)if(i[a]===t)return a;return-1}function G(r,e,u){return u<0&&(u+=r.length,u<0&&(u=0)),q(r)?y(r)?b(r,e,u):A(r)?k(r,e,u):V(r,e,u):S(r,e,u)}o.exports=G
|
|
3
|
+
});var L=f();module.exports=L;
|
|
4
|
+
/** @license Apache-2.0 */
|
|
5
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../lib/main.js", "../lib/index.js"],
|
|
4
|
+
"sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2025 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 isComplexLike = require( '@stdlib/assert-is-complex-like' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar reinterpret = require( '@stdlib/strided-base-reinterpret-complex' );\nvar reinterpretBoolean = require( '@stdlib/strided-base-reinterpret-boolean' );\nvar isComplexTypedArray = require( '@stdlib/array-base-assert-is-complex-typed-array' );\nvar isBooleanArray = require( '@stdlib/array-base-assert-is-booleanarray' );\nvar resolveGetter = require( '@stdlib/array-base-resolve-getter' );\nvar isSameValue = require( '@stdlib/assert-is-same-value' );\nvar real = require( '@stdlib/complex-float64-real' );\nvar imag = require( '@stdlib/complex-float64-imag' );\n\n\n// FUNCTIONS //\n\n/**\n* Returns the index of the first element which equals a provided search element according to the same value algorithm.\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 = indexed( x, 2, 0 );\n* // returns 1\n*/\nfunction indexed( x, searchElement, fromIndex ) {\n\tvar i;\n\tfor ( i = fromIndex; i < x.length; i++ ) {\n\t\tif ( isSameValue( 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 according to the same value algorithm.\n*\n* @private\n* @param {Collection} 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 ( isSameValue( searchElement, get( 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 according to the same value algorithm.\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 Complex128Array = require( '@stdlib/array-complex128' );\n* var Complex128 = require( '@stdlib/complex-float64-ctor' );\n*\n* var x = new Complex128Array( [ 1.0, 2.0, 0.0, 0.0, 3.0, 4.0, 0.0, 0.0 ] );\n*\n* var idx = complex( x, new Complex128( 3.0, 4.0 ), 1 );\n* // returns 2\n*/\nfunction complex( x, searchElement, fromIndex ) {\n\tvar view;\n\tvar re;\n\tvar im;\n\tvar i;\n\tif ( !isComplexLike( searchElement ) ) {\n\t\treturn -1;\n\t}\n\tview = reinterpret( x, 0 );\n\tre = real( searchElement );\n\tim = imag( searchElement );\n\tfor ( i = fromIndex*2; i < view.length; i += 2 ) {\n\t\tif ( isSameValue( view[ i ], re ) && isSameValue( view[ i+1 ], im ) ) {\n\t\t\treturn i / 2;\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 according to the same value algorithm.\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 BooleanArray = require( '@stdlib/array-bool' );\n*\n* var x = new BooleanArray( [ true, false, true, false, true ] );\n*\n* var idx = boolean( x, true, 1 );\n* // returns 2\n*/\nfunction boolean( x, searchElement, fromIndex ) {\n\tvar view;\n\tvar v;\n\tvar i;\n\tif ( !isBoolean( searchElement ) ) {\n\t\treturn -1;\n\t}\n\tview = reinterpretBoolean( x, 0 );\n\tv = ( searchElement ) ? 1 : 0;\n\tfor ( i = fromIndex; i < view.length; i++ ) {\n\t\tif ( view[ i ] === v ) {\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 according to the same value algorithm.\n*\n* ## Notes\n*\n* - The function uses the [SameValue Algorithm][ecma-262-same-value-algorithm], as specified in ECMAScript 5.\n* - In contrast to the strict equality operator `===`, `-0` and `+0` are distinguishable and `NaNs` are the same.\n* - If unable to find an element which equals a provided search element, the function returns `-1`.\n*\n* [ecma-262-same-value-algorithm]: http://ecma-international.org/ecma-262/5.1/#sec-9.12\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 = indexOfSameValue( 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 = indexOfSameValue( x, 2, 0 );\n* // returns 1\n*/\nfunction indexOfSameValue( x, searchElement, fromIndex ) {\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\tif ( isComplexTypedArray( x ) ) {\n\t\t\treturn complex( x, searchElement, fromIndex );\n\t\t}\n\t\tif ( isBooleanArray( x ) ) {\n\t\t\treturn boolean( x, searchElement, fromIndex );\n\t\t}\n\t\treturn accessors( x, searchElement, fromIndex );\n\t}\n\treturn indexed( x, searchElement, fromIndex );\n}\n\n\n// EXPORTS //\n\nmodule.exports = indexOfSameValue;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2025 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 according to the same value algorithm.\n*\n* @module @stdlib/array-base-index-of-same-value\n*\n* @example\n* var indexOfSameValue = require( '@stdlib/array-base-index-of-same-value' );\n*\n* var x = [ 1, 2, 3, 4 ];\n*\n* var idx = indexOfSameValue( 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,gCAAiC,EAC1DC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAc,QAAS,0CAA2C,EAClEC,EAAqB,QAAS,0CAA2C,EACzEC,EAAsB,QAAS,kDAAmD,EAClFC,EAAiB,QAAS,2CAA4C,EACtEC,EAAgB,QAAS,mCAAoC,EAC7DC,EAAc,QAAS,8BAA+B,EACtDC,EAAO,QAAS,8BAA+B,EAC/CC,EAAO,QAAS,8BAA+B,EAoBnD,SAASC,EAASC,EAAGC,EAAeC,EAAY,CAC/C,IAAI,EACJ,IAAM,EAAIA,EAAW,EAAIF,EAAE,OAAQ,IAClC,GAAKJ,EAAaK,EAAeD,EAAG,CAAE,CAAE,EACvC,OAAO,EAGT,MAAO,EACR,CAmBA,SAASG,EAAWH,EAAGC,EAAeC,EAAY,CACjD,IAAIE,EACAC,EAGJ,IADAD,EAAMT,EAAeK,CAAE,EACjBK,EAAIH,EAAWG,EAAIL,EAAE,OAAQK,IAClC,GAAKT,EAAaK,EAAeG,EAAKJ,EAAGK,CAAE,CAAE,EAC5C,OAAOA,EAGT,MAAO,EACR,CAoBA,SAASC,EAASN,EAAGC,EAAeC,EAAY,CAC/C,IAAIK,EACAC,EACAC,EACAJ,EACJ,GAAK,CAAChB,EAAeY,CAAc,EAClC,MAAO,GAKR,IAHAM,EAAOhB,EAAaS,EAAG,CAAE,EACzBQ,EAAKX,EAAMI,CAAc,EACzBQ,EAAKX,EAAMG,CAAc,EACnBI,EAAIH,EAAU,EAAGG,EAAIE,EAAK,OAAQF,GAAK,EAC5C,GAAKT,EAAaW,EAAMF,CAAE,EAAGG,CAAG,GAAKZ,EAAaW,EAAMF,EAAE,CAAE,EAAGI,CAAG,EACjE,OAAOJ,EAAI,EAGb,MAAO,EACR,CAmBA,SAASK,EAASV,EAAGC,EAAeC,EAAY,CAC/C,IAAIK,EACAI,EACAN,EACJ,GAAK,CAACf,EAAWW,CAAc,EAC9B,MAAO,GAIR,IAFAM,EAAOf,EAAoBQ,EAAG,CAAE,EAChCW,EAAMV,EAAkB,EAAI,EACtBI,EAAIH,EAAWG,EAAIE,EAAK,OAAQF,IACrC,GAAKE,EAAMF,CAAE,IAAMM,EAClB,OAAON,EAGT,MAAO,EACR,CAmCA,SAASO,EAAkBZ,EAAGC,EAAeC,EAAY,CAOxD,OANKA,EAAY,IAChBA,GAAaF,EAAE,OACVE,EAAY,IAChBA,EAAY,IAGTd,EAAiBY,CAAE,EAClBP,EAAqBO,CAAE,EACpBM,EAASN,EAAGC,EAAeC,CAAU,EAExCR,EAAgBM,CAAE,EACfU,EAASV,EAAGC,EAAeC,CAAU,EAEtCC,EAAWH,EAAGC,EAAeC,CAAU,EAExCH,EAASC,EAAGC,EAAeC,CAAU,CAC7C,CAKAf,EAAO,QAAUyB,ICtLjB,IAAIC,EAAO,IAKX,OAAO,QAAUA",
|
|
6
|
+
"names": ["require_main", "__commonJSMin", "exports", "module", "isAccessorArray", "isComplexLike", "isBoolean", "reinterpret", "reinterpretBoolean", "isComplexTypedArray", "isBooleanArray", "resolveGetter", "isSameValue", "real", "imag", "indexed", "x", "searchElement", "fromIndex", "accessors", "get", "i", "complex", "view", "re", "im", "boolean", "v", "indexOfSameValue", "main"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2025 The Stdlib Authors.
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
// TypeScript Version: 4.1
|
|
20
|
+
|
|
21
|
+
/// <reference types="@stdlib/types"/>
|
|
22
|
+
|
|
23
|
+
import { Collection, AccessorArrayLike } from '@stdlib/types/array';
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Returns the index of the first element which equals a provided search element according to the same value algorithm.
|
|
27
|
+
*
|
|
28
|
+
* ## Notes
|
|
29
|
+
*
|
|
30
|
+
* - The function uses the [SameValue Algorithm][ecma-262-same-value-algorithm], as specified in ECMAScript 5.
|
|
31
|
+
* - In contrast to the strict equality operator `===`, `-0` and `+0` are distinguishable and `NaNs` are the same.
|
|
32
|
+
* - If unable to find an element which equals a provided search element, the function returns `-1`.
|
|
33
|
+
* - If `fromIndex` is less than zero, the starting index is resolved relative to the last array element, with the last array element corresponding to `fromIndex = -1`.
|
|
34
|
+
*
|
|
35
|
+
* [ecma-262-same-value-algorithm]: http://ecma-international.org/ecma-262/5.1/#sec-9.12
|
|
36
|
+
*
|
|
37
|
+
* @param x - input array
|
|
38
|
+
* @param searchElement - search element
|
|
39
|
+
* @param fromIndex - starting index (inclusive)
|
|
40
|
+
* @returns index
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* var x = [ 1, 2, 3, 4 ];
|
|
44
|
+
*
|
|
45
|
+
* var idx = indexOfSameValue( x, 2, 0 );
|
|
46
|
+
* // returns 1
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* var Int32Array = require( '@stdlib/array-int32' );
|
|
50
|
+
*
|
|
51
|
+
* var x = new Int32Array( [ 1, 2, 3, 4 ] );
|
|
52
|
+
*
|
|
53
|
+
* var idx = indexOfSameValue( x, 2, 0 );
|
|
54
|
+
* // returns 1
|
|
55
|
+
*/
|
|
56
|
+
declare function indexOfSameValue( x: Collection | AccessorArrayLike<unknown>, searchElement: unknown, fromIndex: number ): number;
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
// EXPORTS //
|
|
60
|
+
|
|
61
|
+
export = indexOfSameValue;
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2025 The Stdlib Authors.
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
'use strict';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Return the index of the first element which equals a provided search element according to the same value algorithm.
|
|
23
|
+
*
|
|
24
|
+
* @module @stdlib/array-base-index-of-same-value
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* var indexOfSameValue = require( '@stdlib/array-base-index-of-same-value' );
|
|
28
|
+
*
|
|
29
|
+
* var x = [ 1, 2, 3, 4 ];
|
|
30
|
+
*
|
|
31
|
+
* var idx = indexOfSameValue( x, 2, 0 );
|
|
32
|
+
* // returns 1
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
// MODULES //
|
|
36
|
+
|
|
37
|
+
var main = require( './main.js' );
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
// EXPORTS //
|
|
41
|
+
|
|
42
|
+
module.exports = main;
|
package/lib/main.js
ADDED
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2025 The Stdlib Authors.
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
'use strict';
|
|
20
|
+
|
|
21
|
+
// MODULES //
|
|
22
|
+
|
|
23
|
+
var isAccessorArray = require( '@stdlib/assert-is-accessor-array' );
|
|
24
|
+
var isComplexLike = require( '@stdlib/assert-is-complex-like' );
|
|
25
|
+
var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;
|
|
26
|
+
var reinterpret = require( '@stdlib/strided-base-reinterpret-complex' );
|
|
27
|
+
var reinterpretBoolean = require( '@stdlib/strided-base-reinterpret-boolean' );
|
|
28
|
+
var isComplexTypedArray = require( '@stdlib/array-base-assert-is-complex-typed-array' );
|
|
29
|
+
var isBooleanArray = require( '@stdlib/array-base-assert-is-booleanarray' );
|
|
30
|
+
var resolveGetter = require( '@stdlib/array-base-resolve-getter' );
|
|
31
|
+
var isSameValue = require( '@stdlib/assert-is-same-value' );
|
|
32
|
+
var real = require( '@stdlib/complex-float64-real' );
|
|
33
|
+
var imag = require( '@stdlib/complex-float64-imag' );
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
// FUNCTIONS //
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Returns the index of the first element which equals a provided search element according to the same value algorithm.
|
|
40
|
+
*
|
|
41
|
+
* @private
|
|
42
|
+
* @param {Collection} x - input array
|
|
43
|
+
* @param {*} searchElement - search element
|
|
44
|
+
* @param {NonNegativeInteger} fromIndex - starting index (inclusive)
|
|
45
|
+
* @returns {integer} index
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* var x = [ 1, 2, 3, 4 ];
|
|
49
|
+
*
|
|
50
|
+
* var idx = indexed( x, 2, 0 );
|
|
51
|
+
* // returns 1
|
|
52
|
+
*/
|
|
53
|
+
function indexed( x, searchElement, fromIndex ) {
|
|
54
|
+
var i;
|
|
55
|
+
for ( i = fromIndex; i < x.length; i++ ) {
|
|
56
|
+
if ( isSameValue( searchElement, x[ i ] ) ) {
|
|
57
|
+
return i;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return -1;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Returns the index of the first element which equals a provided search element according to the same value algorithm.
|
|
65
|
+
*
|
|
66
|
+
* @private
|
|
67
|
+
* @param {Collection} x - input array object
|
|
68
|
+
* @param {*} searchElement - search element
|
|
69
|
+
* @param {NonNegativeInteger} fromIndex - starting index (inclusive)
|
|
70
|
+
* @returns {integer} index
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' );
|
|
74
|
+
*
|
|
75
|
+
* var x = toAccessorArray( [ 1, 2, 3, 4 ] );
|
|
76
|
+
*
|
|
77
|
+
* var idx = accessors( x, 2, 0 );
|
|
78
|
+
* // returns 1
|
|
79
|
+
*/
|
|
80
|
+
function accessors( x, searchElement, fromIndex ) {
|
|
81
|
+
var get;
|
|
82
|
+
var i;
|
|
83
|
+
|
|
84
|
+
get = resolveGetter( x );
|
|
85
|
+
for ( i = fromIndex; i < x.length; i++ ) {
|
|
86
|
+
if ( isSameValue( searchElement, get( x, i ) ) ) {
|
|
87
|
+
return i;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return -1;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Returns the index of the first element which equals a provided search element according to the same value algorithm.
|
|
95
|
+
*
|
|
96
|
+
* @private
|
|
97
|
+
* @param {Collection} x - input array
|
|
98
|
+
* @param {*} searchElement - search element
|
|
99
|
+
* @param {NonNegativeInteger} fromIndex - starting index (inclusive)
|
|
100
|
+
* @returns {integer} index
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* var Complex128Array = require( '@stdlib/array-complex128' );
|
|
104
|
+
* var Complex128 = require( '@stdlib/complex-float64-ctor' );
|
|
105
|
+
*
|
|
106
|
+
* var x = new Complex128Array( [ 1.0, 2.0, 0.0, 0.0, 3.0, 4.0, 0.0, 0.0 ] );
|
|
107
|
+
*
|
|
108
|
+
* var idx = complex( x, new Complex128( 3.0, 4.0 ), 1 );
|
|
109
|
+
* // returns 2
|
|
110
|
+
*/
|
|
111
|
+
function complex( x, searchElement, fromIndex ) {
|
|
112
|
+
var view;
|
|
113
|
+
var re;
|
|
114
|
+
var im;
|
|
115
|
+
var i;
|
|
116
|
+
if ( !isComplexLike( searchElement ) ) {
|
|
117
|
+
return -1;
|
|
118
|
+
}
|
|
119
|
+
view = reinterpret( x, 0 );
|
|
120
|
+
re = real( searchElement );
|
|
121
|
+
im = imag( searchElement );
|
|
122
|
+
for ( i = fromIndex*2; i < view.length; i += 2 ) {
|
|
123
|
+
if ( isSameValue( view[ i ], re ) && isSameValue( view[ i+1 ], im ) ) {
|
|
124
|
+
return i / 2;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return -1;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Returns the index of the first element which equals a provided search element according to the same value algorithm.
|
|
132
|
+
*
|
|
133
|
+
* @private
|
|
134
|
+
* @param {Collection} x - input array
|
|
135
|
+
* @param {*} searchElement - search element
|
|
136
|
+
* @param {NonNegativeInteger} fromIndex - starting index (inclusive)
|
|
137
|
+
* @returns {integer} index
|
|
138
|
+
*
|
|
139
|
+
* @example
|
|
140
|
+
* var BooleanArray = require( '@stdlib/array-bool' );
|
|
141
|
+
*
|
|
142
|
+
* var x = new BooleanArray( [ true, false, true, false, true ] );
|
|
143
|
+
*
|
|
144
|
+
* var idx = boolean( x, true, 1 );
|
|
145
|
+
* // returns 2
|
|
146
|
+
*/
|
|
147
|
+
function boolean( x, searchElement, fromIndex ) {
|
|
148
|
+
var view;
|
|
149
|
+
var v;
|
|
150
|
+
var i;
|
|
151
|
+
if ( !isBoolean( searchElement ) ) {
|
|
152
|
+
return -1;
|
|
153
|
+
}
|
|
154
|
+
view = reinterpretBoolean( x, 0 );
|
|
155
|
+
v = ( searchElement ) ? 1 : 0;
|
|
156
|
+
for ( i = fromIndex; i < view.length; i++ ) {
|
|
157
|
+
if ( view[ i ] === v ) {
|
|
158
|
+
return i;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
return -1;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
// MAIN //
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Returns the index of the first element which equals a provided search element according to the same value algorithm.
|
|
169
|
+
*
|
|
170
|
+
* ## Notes
|
|
171
|
+
*
|
|
172
|
+
* - The function uses the [SameValue Algorithm][ecma-262-same-value-algorithm], as specified in ECMAScript 5.
|
|
173
|
+
* - In contrast to the strict equality operator `===`, `-0` and `+0` are distinguishable and `NaNs` are the same.
|
|
174
|
+
* - If unable to find an element which equals a provided search element, the function returns `-1`.
|
|
175
|
+
*
|
|
176
|
+
* [ecma-262-same-value-algorithm]: http://ecma-international.org/ecma-262/5.1/#sec-9.12
|
|
177
|
+
*
|
|
178
|
+
* @param {Collection} x - input array
|
|
179
|
+
* @param {*} searchElement - search element
|
|
180
|
+
* @param {integer} fromIndex - starting index (inclusive)
|
|
181
|
+
* @returns {integer} index
|
|
182
|
+
*
|
|
183
|
+
* @example
|
|
184
|
+
* var x = [ 1, 2, 3, 4 ];
|
|
185
|
+
*
|
|
186
|
+
* var idx = indexOfSameValue( x, 2, 0 );
|
|
187
|
+
* // returns 1
|
|
188
|
+
*
|
|
189
|
+
* @example
|
|
190
|
+
* var Int32Array = require( '@stdlib/array-int32' );
|
|
191
|
+
*
|
|
192
|
+
* var x = new Int32Array( [ 1, 2, 3, 4 ] );
|
|
193
|
+
*
|
|
194
|
+
* var idx = indexOfSameValue( x, 2, 0 );
|
|
195
|
+
* // returns 1
|
|
196
|
+
*/
|
|
197
|
+
function indexOfSameValue( x, searchElement, fromIndex ) {
|
|
198
|
+
if ( fromIndex < 0 ) {
|
|
199
|
+
fromIndex += x.length;
|
|
200
|
+
if ( fromIndex < 0 ) {
|
|
201
|
+
fromIndex = 0;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
if ( isAccessorArray( x ) ) {
|
|
205
|
+
if ( isComplexTypedArray( x ) ) {
|
|
206
|
+
return complex( x, searchElement, fromIndex );
|
|
207
|
+
}
|
|
208
|
+
if ( isBooleanArray( x ) ) {
|
|
209
|
+
return boolean( x, searchElement, fromIndex );
|
|
210
|
+
}
|
|
211
|
+
return accessors( x, searchElement, fromIndex );
|
|
212
|
+
}
|
|
213
|
+
return indexed( x, searchElement, fromIndex );
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
// EXPORTS //
|
|
218
|
+
|
|
219
|
+
module.exports = indexOfSameValue;
|
package/package.json
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@stdlib/array-base-index-of-same-value",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Return the index of the first element which equals a provided search element according to the same value algorithm.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"author": {
|
|
7
|
+
"name": "The Stdlib Authors",
|
|
8
|
+
"url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
|
|
9
|
+
},
|
|
10
|
+
"contributors": [
|
|
11
|
+
{
|
|
12
|
+
"name": "The Stdlib Authors",
|
|
13
|
+
"url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
|
|
14
|
+
}
|
|
15
|
+
],
|
|
16
|
+
"main": "./lib",
|
|
17
|
+
"directories": {
|
|
18
|
+
"doc": "./docs",
|
|
19
|
+
"lib": "./lib",
|
|
20
|
+
"dist": "./dist"
|
|
21
|
+
},
|
|
22
|
+
"types": "./docs/types",
|
|
23
|
+
"scripts": {},
|
|
24
|
+
"homepage": "https://stdlib.io",
|
|
25
|
+
"repository": {
|
|
26
|
+
"type": "git",
|
|
27
|
+
"url": "git://github.com/stdlib-js/array-base-index-of-same-value.git"
|
|
28
|
+
},
|
|
29
|
+
"bugs": {
|
|
30
|
+
"url": "https://github.com/stdlib-js/stdlib/issues"
|
|
31
|
+
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@stdlib/array-base-assert-is-booleanarray": "^0.0.2",
|
|
34
|
+
"@stdlib/array-base-assert-is-complex-typed-array": "^0.1.2",
|
|
35
|
+
"@stdlib/array-base-resolve-getter": "^0.2.2",
|
|
36
|
+
"@stdlib/assert-is-accessor-array": "^0.2.2",
|
|
37
|
+
"@stdlib/assert-is-boolean": "^0.2.2",
|
|
38
|
+
"@stdlib/assert-is-complex-like": "^0.2.2",
|
|
39
|
+
"@stdlib/assert-is-same-value": "^0.2.2",
|
|
40
|
+
"@stdlib/complex-float64-imag": "^0.1.1",
|
|
41
|
+
"@stdlib/complex-float64-real": "^0.1.1",
|
|
42
|
+
"@stdlib/strided-base-reinterpret-boolean": "^0.0.2",
|
|
43
|
+
"@stdlib/strided-base-reinterpret-complex": "^0.1.2"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {},
|
|
46
|
+
"engines": {
|
|
47
|
+
"node": ">=0.10.0",
|
|
48
|
+
"npm": ">2.7.0"
|
|
49
|
+
},
|
|
50
|
+
"os": [
|
|
51
|
+
"aix",
|
|
52
|
+
"darwin",
|
|
53
|
+
"freebsd",
|
|
54
|
+
"linux",
|
|
55
|
+
"macos",
|
|
56
|
+
"openbsd",
|
|
57
|
+
"sunos",
|
|
58
|
+
"win32",
|
|
59
|
+
"windows"
|
|
60
|
+
],
|
|
61
|
+
"keywords": [
|
|
62
|
+
"stdlib",
|
|
63
|
+
"stdtypes",
|
|
64
|
+
"types",
|
|
65
|
+
"data",
|
|
66
|
+
"structure",
|
|
67
|
+
"array",
|
|
68
|
+
"generic",
|
|
69
|
+
"search",
|
|
70
|
+
"find",
|
|
71
|
+
"scan",
|
|
72
|
+
"locate",
|
|
73
|
+
"index",
|
|
74
|
+
"same"
|
|
75
|
+
],
|
|
76
|
+
"funding": {
|
|
77
|
+
"type": "opencollective",
|
|
78
|
+
"url": "https://opencollective.com/stdlib"
|
|
79
|
+
}
|
|
80
|
+
}
|