One, the combined de-weight of two arrays:
vararr1 = [' A ', ' B '];varARR2 = [' A ', ' C ', ' d '];varARR3 = [1, ' d ', undefined,true,NULL];//merge two arrays, go to heavyvarConcat_ =function(ARR1,ARR2) {//do not directly use the var arr = arr1, so that arr is only a reference to ARR1, and the modifications of both will affect each other vararr =Arr1.concat (); //or use slice () to copy, var arr = arr1.slice (0) for(vari=0;i<arr2.length;i++) {arr.indexof (arr2[i])= = =-1? Arr.push (Arr2[i]): 0; } returnarr;} Console.log (Concat_ (ARR1,ARR2)); //[' A ', ' B ', ' C ', ' d ']
Two, the merging of multiple arrays to remove weight:
vararr1 = [' A ', ' B '];varARR2 = [' A ', ' C ', ' d '];varARR3 = [1, ' d ', undefined,true,NULL];//merge multiple arrays, go to heavyvarConcat_ =function(ARR1,ARR2,ARR3) {if(Arguments.length <= 1){ return false; } varConcat_ =function(ARR1,ARR2) {vararr =Arr1.concat (); for(vari=0;i<arr2.length;i++) {arr.indexof (arr2[i])= = =-1? Arr.push (Arr2[i]): 0; } returnarr; } varresult =Concat_ (ARR1,ARR2); for(vari=2;i<arguments.length;i++) {result=Concat_ (Result,arguments[i]); } returnresult;} Console.log (Concat_ (ARR1,ARR2,ARR3));//["A", "B", "C", "D", 1, undefined, true, NULL]
Three, multiple arrays merged, de-heavy, sort:
//merge multiple arrays, go to heavy, sortvarARR1 = [1,6,4,0];varARR2 = [8,20,7,4.5];varARR3 = [6,0,7,90,2];varConcat_ =function(ARR1,ARR2,ARR3) {if(Arguments.length <= 1){ return false; } varConcat_ =function(ARR1,ARR2) {vararr =Arr1.concat (); for(vari=0;i<arr2.length;i++) {arr.indexof (arr2[i])= = =-1? Arr.push (Arr2[i]): 0; } returnarr; } varresult =Concat_ (ARR1,ARR2); for(vari=2;i<arguments.length;i++) {result=Concat_ (Result,arguments[i]); } //Sort functionSortnumber (A, b) {returnAb; } returnResult.sort (sortnumber);} Console.log (Concat_ (ARR1,ARR2,ARR3))//[0, 1, 2, 4, 4.5, 6, 7, 8, +--]
Reference:
http://m.blog.csdn.net/article/details?id=49634041
Merging of arrays, de-weight, sorting