source: node_modules/ramda/es/internal/_indexOf.js@ d24f17c

main
Last change on this file since d24f17c was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Initial commit

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