Skip to main content

Bug Tracker

Side navigation

Ticket #1157: array_diff.patch


File array_diff.patch, 0.9 KB (added by bermi, May 02, 2007 05:18PM UTC)
Index: jquery/src/jquery/jquery.js
===================================================================
--- jquery/src/jquery/jquery.js	(revision 1854)
+++ jquery/src/jquery/jquery.js	(working copy)
@@ -1759,6 +1759,29 @@
 		}
 
 		return result;
+	},
+	
+	/**
+	 * Compares two or more arrays, and returns an array with the values 
+	 * from the first array, only if the value is not present in the 
+	 * second array
+	 * 
+	 * @example $.diff( ['a','b','c'], ['b','d','e'] )
+	 * @result ['a','b']
+	 * @desc Compares two or more arrays, and returns an array with the values 
+	 * from the first array
+	 *
+	 * @name $.merge
+	 * @type Array
+	 * @param Array first The array to be filtered.
+	 * @param Array second The second array contains the items that need 
+	 * to be removed from the first array.
+	 * @cat JavaScript
+	 */
+	diff: function(a, b){
+	    return jQuery.grep(a, function(n,i){
+			return b.indexOf(n) < 0; 
+		});
 	}
 });

Download in other formats:

Original Format