1 var arraySome = require('./_arraySome');
3 /** Used to compose bitmasks for comparison styles. */
4 var UNORDERED_COMPARE_FLAG = 1,
5 PARTIAL_COMPARE_FLAG = 2;
8 * A specialized version of `baseIsEqualDeep` for arrays with support for
9 * partial deep comparisons.
12 * @param {Array} array The array to compare.
13 * @param {Array} other The other array to compare.
14 * @param {Function} equalFunc The function to determine equivalents of values.
15 * @param {Function} [customizer] The function to customize comparisons.
16 * @param {number} [bitmask] The bitmask of comparison flags. See `baseIsEqual` for more details.
17 * @param {Object} [stack] Tracks traversed `array` and `other` objects.
18 * @returns {boolean} Returns `true` if the arrays are equivalent, else `false`.
20 function equalArrays(array, other, equalFunc, customizer, bitmask, stack) {
22 isPartial = bitmask & PARTIAL_COMPARE_FLAG,
23 isUnordered = bitmask & UNORDERED_COMPARE_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);
33 return stacked == other;
36 stack.set(array, other);
38 // Ignore non-index properties.
39 while (++index < arrLength) {
40 var arrValue = array[index],
41 othValue = other[index];
44 var compared = isPartial
45 ? customizer(othValue, arrValue, index, other, array, stack)
46 : customizer(arrValue, othValue, index, array, other, stack);
48 if (compared !== undefined) {
55 // Recursively compare arrays (susceptible to call stack limits).
57 if (!arraySome(other, function(othValue) {
58 return arrValue === othValue || equalFunc(arrValue, othValue, customizer, bitmask, stack);
63 } else if (!(arrValue === othValue || equalFunc(arrValue, othValue, customizer, bitmask, stack))) {
68 stack['delete'](array);
72 module.exports = equalArrays;