Initial commit
[yaffs-website] / node_modules / node-sass / node_modules / lodash / _equalArrays.js
1 var SetCache = require('./_SetCache'),
2     arraySome = require('./_arraySome'),
3     cacheHas = require('./_cacheHas');
4
5 /** Used to compose bitmasks for comparison styles. */
6 var UNORDERED_COMPARE_FLAG = 1,
7     PARTIAL_COMPARE_FLAG = 2;
8
9 /**
10  * A specialized version of `baseIsEqualDeep` for arrays with support for
11  * partial deep comparisons.
12  *
13  * @private
14  * @param {Array} array The array to compare.
15  * @param {Array} other The other array to compare.
16  * @param {Function} equalFunc The function to determine equivalents of values.
17  * @param {Function} customizer The function to customize comparisons.
18  * @param {number} bitmask The bitmask of comparison flags. See `baseIsEqual`
19  *  for more details.
20  * @param {Object} stack Tracks traversed `array` and `other` objects.
21  * @returns {boolean} Returns `true` if the arrays are equivalent, else `false`.
22  */
23 function equalArrays(array, other, equalFunc, customizer, bitmask, stack) {
24   var isPartial = bitmask & PARTIAL_COMPARE_FLAG,
25       arrLength = array.length,
26       othLength = other.length;
27
28   if (arrLength != othLength && !(isPartial && othLength > arrLength)) {
29     return false;
30   }
31   // Assume cyclic values are equal.
32   var stacked = stack.get(array);
33   if (stacked && stack.get(other)) {
34     return stacked == other;
35   }
36   var index = -1,
37       result = true,
38       seen = (bitmask & UNORDERED_COMPARE_FLAG) ? new SetCache : undefined;
39
40   stack.set(array, other);
41   stack.set(other, array);
42
43   // Ignore non-index properties.
44   while (++index < arrLength) {
45     var arrValue = array[index],
46         othValue = other[index];
47
48     if (customizer) {
49       var compared = isPartial
50         ? customizer(othValue, arrValue, index, other, array, stack)
51         : customizer(arrValue, othValue, index, array, other, stack);
52     }
53     if (compared !== undefined) {
54       if (compared) {
55         continue;
56       }
57       result = false;
58       break;
59     }
60     // Recursively compare arrays (susceptible to call stack limits).
61     if (seen) {
62       if (!arraySome(other, function(othValue, othIndex) {
63             if (!cacheHas(seen, othIndex) &&
64                 (arrValue === othValue || equalFunc(arrValue, othValue, customizer, bitmask, stack))) {
65               return seen.push(othIndex);
66             }
67           })) {
68         result = false;
69         break;
70       }
71     } else if (!(
72           arrValue === othValue ||
73             equalFunc(arrValue, othValue, customizer, bitmask, stack)
74         )) {
75       result = false;
76       break;
77     }
78   }
79   stack['delete'](array);
80   stack['delete'](other);
81   return result;
82 }
83
84 module.exports = equalArrays;