// Array Function Extension array. prototype. each = function (FN) {fn = FN | function. k; var A = []; var ARGs = array. prototype. slice. call (arguments, 1); For (VAR I = 0; I <this. length; I ++) {var res = fn. apply (this, [this [I], I]. concat (ARGs); If (res! = NULL). push (RES) ;}return A ;}; // whether the array contains the specified element array. prototype. contains = function (suarr) {for (VAR I = 0; I <this. length; I ++) {If (this [I] = suarr) {return true ;}return false ;}// array consisting of non-repeating elements. prototype. uniqustme = function () {var Ra = new array (); For (VAR I = 0; I <this. length; I ++) {If (! RA. contains (this [I]) {Ra. push (this [I]) ;}} return Ra ;}; // The complement set of the two arrays array. complement = function (a, B) {return array. minus (array. union (a, B), array. intersect (a, B) ;}; // the intersection of the two arrays array. intersect = function (a, B) {return. uniqustme (). each (function (o) {return B. contains (o )? O: NULL}) ;}; // The difference set array of the two arrays. minus = function (a, B) {return. uniqustme (). each (function (o) {return B. contains (o )? Null: O}) ;}; // array. Union = function (a, B) {return a. Concat (B). uniquelize ();};
This article from the "Dream think Xi" blog, please be sure to keep this source http://qiangmzsx.blog.51cto.com/2052549/1549392
Array Function Extension-difference set, Union set, collection, deduplication