Index: trunk/extensions/VisualEditor/modules/es/es.js |
— | — | @@ -81,6 +81,36 @@ |
82 | 82 | }; |
83 | 83 | |
84 | 84 | /** |
| 85 | + * Recursively compare two arrays. |
| 86 | + * |
| 87 | + * @static |
| 88 | + * @method |
| 89 | + * @param {Array} a First array to compare |
| 90 | + * @param {Array} b Second array to compare |
| 91 | + * @param {Boolean} [compareObjects] If true, use es.compareObjects() to compare objects, otherwise use === |
| 92 | + */ |
| 93 | +es.compareArrays = function( a, b, compareObjects ) { |
| 94 | + var i, aValue, bValue, aType, bType; |
| 95 | + if ( a.length !== b.length ) { |
| 96 | + return false; |
| 97 | + } |
| 98 | + for ( i = 0; i < a.length; i++ ) { |
| 99 | + aValue = a[i]; |
| 100 | + bValue = b[i]; |
| 101 | + aType = typeof aValue; |
| 102 | + bType = typeof bValue; |
| 103 | + if ( aType !== bType || !( |
| 104 | + ( es.isArray( aValue ) && es.isArray( bValue ) && es.compareArrays( aValue, bValue ) ) || |
| 105 | + ( compareObjects && es.isPlainObject( aValue ) && es.compareObjects( aValue, bValue ) ) || |
| 106 | + aValue === bValue |
| 107 | + ) ) { |
| 108 | + return false; |
| 109 | + } |
| 110 | + } |
| 111 | + return true; |
| 112 | +}; |
| 113 | + |
| 114 | +/** |
85 | 115 | * Gets a deep copy of an array's string, number, array and plain-object contents. |
86 | 116 | * |
87 | 117 | * @static |