Gets a concrete implementation of the values of three arrays that do not repeat

  • 2020-03-30 01:12:09
  • OfStack

 
var a = [ "a" , "b" , "c" ], 
b = [ "b" , "c" , "d" ], 
c = [ "c" , "d" , "e" ], 
_a = a.concat( b ).concat( c ), 
_hash = {}, 
_new = []; 
for( var i = _a.length; i--; ){ 
if( !_hash[ _a[ i ] ] ){ 
_hash[ _a[ i ] ] = 1; 
_new.push( _a[ i ] ); 
}; 
}; 
return _new; 

Idea: concatenate an array with concat, then use an object and a new array (for non-repeating arrays).

Iterate through the old array, putting the values into the object, putting the values into the new array if they differ, and not repeating them.

Related articles: