00001 var SetCache = require('./_SetCache'),
00002 arraySome = require('./_arraySome'),
00003 cacheHas = require('./_cacheHas');
00004
00006 var COMPARE_PARTIAL_FLAG = 1,
00007 COMPARE_UNORDERED_FLAG = 2;
00008
00022 function equalArrays(array, other, bitmask, customizer, equalFunc, stack) {
00023 var isPartial = bitmask & COMPARE_PARTIAL_FLAG,
00024 arrLength = array.length,
00025 othLength = other.length;
00026
00027 if (arrLength != othLength && !(isPartial && othLength > arrLength)) {
00028 return false;
00029 }
00030
00031 var stacked = stack.get(array);
00032 if (stacked && stack.get(other)) {
00033 return stacked == other;
00034 }
00035 var index = -1,
00036 result = true,
00037 seen = (bitmask & COMPARE_UNORDERED_FLAG) ? new SetCache : undefined;
00038
00039 stack.set(array, other);
00040 stack.set(other, array);
00041
00042
00043 while (++index < arrLength) {
00044 var arrValue = array[index],
00045 othValue = other[index];
00046
00047 if (customizer) {
00048 var compared = isPartial
00049 ? customizer(othValue, arrValue, index, other, array, stack)
00050 : customizer(arrValue, othValue, index, array, other, stack);
00051 }
00052 if (compared !== undefined) {
00053 if (compared) {
00054 continue;
00055 }
00056 result = false;
00057 break;
00058 }
00059
00060 if (seen) {
00061 if (!arraySome(other, function(othValue, othIndex) {
00062 if (!cacheHas(seen, othIndex) &&
00063 (arrValue === othValue || equalFunc(arrValue, othValue, bitmask, customizer, stack))) {
00064 return seen.push(othIndex);
00065 }
00066 })) {
00067 result = false;
00068 break;
00069 }
00070 } else if (!(
00071 arrValue === othValue ||
00072 equalFunc(arrValue, othValue, bitmask, customizer, stack)
00073 )) {
00074 result = false;
00075 break;
00076 }
00077 }
00078 stack['delete'](array);
00079 stack['delete'](other);
00080 return result;
00081 }
00082
00083 module.exports = equalArrays;