1 var SetCache = require('./_SetCache'),
2 arraySome = require('./_arraySome'),
3 cacheHas = require('./_cacheHas');
5 /** Used to compose bitmasks for value comparisons. */
6 var COMPARE_PARTIAL_FLAG = 1,
7 COMPARE_UNORDERED_FLAG = 2;
10 * A specialized version of `baseIsEqualDeep` for arrays with support for
11 * partial deep comparisons.
14 * @param {Array} array The array to compare.
15 * @param {Array} other The other array to compare.
16 * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
17 * @param {Function} customizer The function to customize comparisons.
18 * @param {Function} equalFunc The function to determine equivalents of values.
19 * @param {Object} stack Tracks traversed `array` and `other` objects.
20 * @returns {boolean} Returns `true` if the arrays are equivalent, else `false`.
22 function equalArrays(array, other, bitmask, customizer, equalFunc, stack) {
23 var isPartial = bitmask & COMPARE_PARTIAL_FLAG,
24 arrLength = array.length,
25 othLength = other.length;
27 if (arrLength != othLength && !(isPartial && othLength > arrLength)) {
30 // Assume cyclic values are equal.
31 var stacked = stack.get(array);
32 if (stacked && stack.get(other)) {
33 return stacked == other;
37 seen = (bitmask & COMPARE_UNORDERED_FLAG) ? new SetCache : undefined;
39 stack.set(array, other);
40 stack.set(other, array);
42 // Ignore non-index properties.
43 while (++index < arrLength) {
44 var arrValue = array[index],
45 othValue = other[index];
48 var compared = isPartial
49 ? customizer(othValue, arrValue, index, other, array, stack)
50 : customizer(arrValue, othValue, index, array, other, stack);
52 if (compared !== undefined) {
59 // Recursively compare arrays (susceptible to call stack limits).
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);
71 arrValue === othValue ||
72 equalFunc(arrValue, othValue, bitmask, customizer, stack)
78 stack['delete'](array);
79 stack['delete'](other);
83 module.exports = equalArrays;