1 | var equals =
|
2 |
|
3 | require("../equals");
|
4 |
|
5 | function _indexOf(list, a, idx) {
|
6 | var inf, item;
|
7 |
|
8 | if (typeof list.indexOf === 'function') {
|
9 | switch (typeof a) {
|
10 | case 'number':
|
11 | if (a === 0) {
|
12 |
|
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 |
|
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 | }
|
40 |
|
41 |
|
42 | return list.indexOf(a, idx);
|
43 |
|
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 |
|
54 | return list.indexOf(a, idx);
|
55 | }
|
56 |
|
57 | }
|
58 | }
|
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; |
\ | No newline at end of file |