1 var SetCache = require('./_SetCache'),
2 arraySome = require('./_arraySome'),
3 cacheHas = require('./_cacheHas');
5 /** Used to compose bitmasks for comparison styles. */
6 var UNORDERED_COMPARE_FLAG = 1,
7 PARTIAL_COMPARE_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 {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`
20 * @param {Object} stack Tracks traversed `array` and `other` objects.
21 * @returns {boolean} Returns `true` if the arrays are equivalent, else `false`.
23 function equalArrays(array, other, equalFunc, customizer, bitmask, stack) {
24 var isPartial = bitmask & PARTIAL_COMPARE_FLAG,
25 arrLength = array.length,
26 othLength = other.length;
28 if (arrLength != othLength && !(isPartial && othLength > arrLength)) {
31 // Assume cyclic values are equal.
32 var stacked = stack.get(array);
33 if (stacked && stack.get(other)) {
34 return stacked == other;
38 seen = (bitmask & UNORDERED_COMPARE_FLAG) ? new SetCache : undefined;
40 stack.set(array, other);
41 stack.set(other, array);
43 // Ignore non-index properties.
44 while (++index < arrLength) {
45 var arrValue = array[index],
46 othValue = other[index];
49 var compared = isPartial
50 ? customizer(othValue, arrValue, index, other, array, stack)
51 : customizer(arrValue, othValue, index, array, other, stack);
53 if (compared !== undefined) {
60 // Recursively compare arrays (susceptible to call stack limits).
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);
72 arrValue === othValue ||
73 equalFunc(arrValue, othValue, customizer, bitmask, stack)
79 stack['delete'](array);
80 stack['delete'](other);
84 module.exports = equalArrays;