main
Last change
on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago |
Initial commit
|
-
Property mode
set to
100644
|
File size:
1.4 KB
|
Line | |
---|
1 | var equals =
|
---|
2 | /*#__PURE__*/
|
---|
3 | require("../equals.js");
|
---|
4 |
|
---|
5 | function _indexOf(list, a, idx) {
|
---|
6 | var inf, item; // Array.prototype.indexOf doesn't exist below IE9
|
---|
7 |
|
---|
8 | if (typeof list.indexOf === 'function') {
|
---|
9 | switch (typeof a) {
|
---|
10 | case 'number':
|
---|
11 | if (a === 0) {
|
---|
12 | // manually crawl the list to distinguish between +0 and -0
|
---|
13 | inf = 1 / a;
|
---|
14 |
|
---|
15 | while (idx < list.length) {
|
---|
16 | item = list[idx];
|
---|
17 |
|
---|
18 | if (item === 0 && 1 / item === inf) {
|
---|
19 | return idx;
|
---|
20 | }
|
---|
21 |
|
---|
22 | idx += 1;
|
---|
23 | }
|
---|
24 |
|
---|
25 | return -1;
|
---|
26 | } else if (a !== a) {
|
---|
27 | // NaN
|
---|
28 | while (idx < list.length) {
|
---|
29 | item = list[idx];
|
---|
30 |
|
---|
31 | if (typeof item === 'number' && item !== item) {
|
---|
32 | return idx;
|
---|
33 | }
|
---|
34 |
|
---|
35 | idx += 1;
|
---|
36 | }
|
---|
37 |
|
---|
38 | return -1;
|
---|
39 | } // non-zero numbers can utilise Set
|
---|
40 |
|
---|
41 |
|
---|
42 | return list.indexOf(a, idx);
|
---|
43 | // all these types can utilise Set
|
---|
44 |
|
---|
45 | case 'string':
|
---|
46 | case 'boolean':
|
---|
47 | case 'function':
|
---|
48 | case 'undefined':
|
---|
49 | return list.indexOf(a, idx);
|
---|
50 |
|
---|
51 | case 'object':
|
---|
52 | if (a === null) {
|
---|
53 | // null can utilise Set
|
---|
54 | return list.indexOf(a, idx);
|
---|
55 | }
|
---|
56 |
|
---|
57 | }
|
---|
58 | } // anything else not covered above, defer to R.equals
|
---|
59 |
|
---|
60 |
|
---|
61 | while (idx < list.length) {
|
---|
62 | if (equals(list[idx], a)) {
|
---|
63 | return idx;
|
---|
64 | }
|
---|
65 |
|
---|
66 | idx += 1;
|
---|
67 | }
|
---|
68 |
|
---|
69 | return -1;
|
---|
70 | }
|
---|
71 |
|
---|
72 | module.exports = _indexOf; |
---|
Note:
See
TracBrowser
for help on using the repository browser.