/*** Each is a set iteration function that accepts a function as a parameter and a set of optional parameters * This iteration function calculates each element and optional parameter of the set using a function in sequence, return the calculated result set {% example <SCRIPT> var A = [1, 2, 4]. each (function (x) {return x> 2? X: NULL}); var B = [1, 2, 4]. Each (function (x) {return x <0? X: NULL}); alert (a); alert (B ); </SCRIPT> %} * @ Param {function} FN indicates the function for iterative determination * @ Param more... zero or multiple optional User-Defined parameters * @ returns {array} result set. If no result exists, empty Set */array is returned. 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 ;}; /*** get an array of elements that are not repeated <br/> * uniquely define an array * @ returns {array} an array composed of Non-repeated elements */array. 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 ;};/*** calculate the complement set of the Two sets {% example <SCRIPT> var A = [1, 2, 4]; vaR B = [3, 4, 5, 6]; alert (array. complement (a, B )); </SCRIPT> %} * @ Param {array} a set a * @ Param {array} B Set B * @ returns {array} complement set */array. complement = function (a, B) {return array. minus (array. union (a, B), array. intersect (a, B) ;};/*** calculates the intersection of the two sets {% example <SCRIPT> var A = [1, 2, 3, 4]; var B = [3, 4, 5, 6 ]; Alert (array. intersect (a, B )); </SCRIPT> %} * @ Param {array} a collection a * @ Param {array} B collection B * @ returns {array} intersection of two sets */array. intersect = function (a, B) {return. uniqustme (). each (function (o) {return B. contains (o )? O: NULL}) ;};/*** calculate the difference set {% example <SCRIPT> var A = [1, 2, 3, 4] of the Two sets; var B = [3, 4, 5, 6]; alert (array. minus (a, B )); </SCRIPT> %} * @ Param {array} a set a * @ Param {array} B Set B * @ returns {array} The difference set of the Two sets */array. minus = function (a, B) {return. uniqustme (). each (function (o) {return B. contains (o )? Null: O}) ;};/*** calculate the union of the two sets {% example <SCRIPT> var A = [1, 2, 3, 4]; var B = [3, 4, 5, 6]; alert (array. union (a, B )); </SCRIPT> %} * @ Param {array} a collection a * @ Param {array} B collection B * @ returns {array} the union of the two sets */array. union = function (a, B) {return. concat (B ). uniqustme ();};