r103149 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r103148‎ | r103149 | r103150 >
Date:11:10, 15 November 2011
Author:catrope
Status:deferred
Tags:
Comment:
Add es.compareArrays(), needed for test cases I'm about to add
Modified paths:
  • /trunk/extensions/VisualEditor/modules/es/es.js (modified) (history)

Diff [purge]

Index: trunk/extensions/VisualEditor/modules/es/es.js
@@ -81,6 +81,36 @@
8282 };
8383
8484 /**
 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+/**
85115 * Gets a deep copy of an array's string, number, array and plain-object contents.
86116 *
87117 * @static

Status & tagging log