Permalink
Browse files

Array.diff => Array#diff

  • Loading branch information...
1 parent 4249bf1 commit be24c22a7902cb9dc08d14c318e7be48e227d412 Oliver Morgan committed Sep 29, 2011
Showing with 11 additions and 11 deletions.
  1. +11 −11 lib/array.js
View
@@ -15,16 +15,6 @@ extend(Array, {
*
* @returns array
*/
- if (arguments.length > 1)
- arrays = Array.prototype.slice.call(arguments);
- else if (arguments.length === 0 || arrays.length === 0)
- return [];
-
- var vals = arrays.flatten(1);
-
- return vals.filter(function(a) {
- return vals.indexOf(a) == vals.lastIndexOf(a);
- });
},
union: function union(arrays) {
@@ -318,14 +308,24 @@ extend(Array.prototype, {
*
* @since 1.0.0
* @alias difference
+ * @updated 1.6.0
+ * Integrated Array.diff into this method if the user didn't supply any arguments.
+ *
* @param *arrays The arrays to differentiate with
* @example
* [1,2,3].diff([2,3,4], [3,4,5]);
* // returns [1,5]
*
+ * [[1,2,3], [2,3,4], [3,4,5]].diff();
+ * // returns [1,5]
+ *
* @returns array
*/
- return Array.diff(Array.prototype.slice.call(arguments).concat([this]));
+ var arrays = (arguments.length === 0) ? this : Array.prototype.slice.call(arguments);
+
+ return arrays.flatten(1).filter(function(a,i,t) {
+ return t.indexOf(a) === t.lastIndexOf(a);
+ });
},
union: function union() {

0 comments on commit be24c22

Please sign in to comment.