0b032ac6a9e73fa42e4a975eb5e5f4d82c331f43
[platform/framework/web/crosswalk-tizen.git] /
1 /**
2  * A specialized version of `baseIsEqualDeep` for arrays with support for
3  * partial deep comparisons.
4  *
5  * @private
6  * @param {Array} array The array to compare.
7  * @param {Array} other The other array to compare.
8  * @param {Function} equalFunc The function to determine equivalents of values.
9  * @param {Function} [customizer] The function to customize comparing arrays.
10  * @param {boolean} [isLoose] Specify performing partial comparisons.
11  * @param {Array} [stackA] Tracks traversed `value` objects.
12  * @param {Array} [stackB] Tracks traversed `other` objects.
13  * @returns {boolean} Returns `true` if the arrays are equivalent, else `false`.
14  */
15 function equalArrays(array, other, equalFunc, customizer, isLoose, stackA, stackB) {
16   var index = -1,
17       arrLength = array.length,
18       othLength = other.length,
19       result = true;
20
21   if (arrLength != othLength && !(isLoose && othLength > arrLength)) {
22     return false;
23   }
24   // Deep compare the contents, ignoring non-numeric properties.
25   while (result && ++index < arrLength) {
26     var arrValue = array[index],
27         othValue = other[index];
28
29     result = undefined;
30     if (customizer) {
31       result = isLoose
32         ? customizer(othValue, arrValue, index)
33         : customizer(arrValue, othValue, index);
34     }
35     if (result === undefined) {
36       // Recursively compare arrays (susceptible to call stack limits).
37       if (isLoose) {
38         var othIndex = othLength;
39         while (othIndex--) {
40           othValue = other[othIndex];
41           result = (arrValue && arrValue === othValue) || equalFunc(arrValue, othValue, customizer, isLoose, stackA, stackB);
42           if (result) {
43             break;
44           }
45         }
46       } else {
47         result = (arrValue && arrValue === othValue) || equalFunc(arrValue, othValue, customizer, isLoose, stackA, stackB);
48       }
49     }
50   }
51   return !!result;
52 }
53
54 module.exports = equalArrays;