1 | var SetCache = require('./_SetCache'),
|
2 | arraySome = require('./_arraySome'),
|
3 | cacheHas = require('./_cacheHas');
|
4 |
|
5 |
|
6 | var COMPARE_PARTIAL_FLAG = 1,
|
7 | COMPARE_UNORDERED_FLAG = 2;
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 | function equalArrays(array, other, bitmask, customizer, equalFunc, stack) {
|
23 | var isPartial = bitmask & COMPARE_PARTIAL_FLAG,
|
24 | arrLength = array.length,
|
25 | othLength = other.length;
|
26 |
|
27 | if (arrLength != othLength && !(isPartial && othLength > arrLength)) {
|
28 | return false;
|
29 | }
|
30 |
|
31 | var stacked = stack.get(array);
|
32 | if (stacked && stack.get(other)) {
|
33 | return stacked == other;
|
34 | }
|
35 | var index = -1,
|
36 | result = true,
|
37 | seen = (bitmask & COMPARE_UNORDERED_FLAG) ? new SetCache : undefined;
|
38 |
|
39 | stack.set(array, other);
|
40 | stack.set(other, array);
|
41 |
|
42 |
|
43 | while (++index < arrLength) {
|
44 | var arrValue = array[index],
|
45 | othValue = other[index];
|
46 |
|
47 | if (customizer) {
|
48 | var compared = isPartial
|
49 | ? customizer(othValue, arrValue, index, other, array, stack)
|
50 | : customizer(arrValue, othValue, index, array, other, stack);
|
51 | }
|
52 | if (compared !== undefined) {
|
53 | if (compared) {
|
54 | continue;
|
55 | }
|
56 | result = false;
|
57 | break;
|
58 | }
|
59 |
|
60 | if (seen) {
|
61 | if (!arraySome(other, function(othValue, othIndex) {
|
62 | if (!cacheHas(seen, othIndex) &&
|
63 | (arrValue === othValue || equalFunc(arrValue, othValue, bitmask, customizer, stack))) {
|
64 | return seen.push(othIndex);
|
65 | }
|
66 | })) {
|
67 | result = false;
|
68 | break;
|
69 | }
|
70 | } else if (!(
|
71 | arrValue === othValue ||
|
72 | equalFunc(arrValue, othValue, bitmask, customizer, stack)
|
73 | )) {
|
74 | result = false;
|
75 | break;
|
76 | }
|
77 | }
|
78 | stack['delete'](array);
|
79 | stack['delete'](other);
|
80 | return result;
|
81 | }
|
82 |
|
83 | module.exports = equalArrays;
|