Skip to content

Instantly share code, notes, and snippets.

{
"singleQuote": true,
"useTabs": true,
"tabWidth": 2,
"trailingComma": "es5",
"endOfLine": "lf",
"printWidth": 80,
"semi": true
}
@nicolasmendonca
nicolasmendonca / union.js
Last active March 17, 2019 12:38 — forked from Bradshaw/union.js
Joins two arrays while removing duplicate items
Array.prototype.union = ( array ) => {
const concatenated = this.concat( array );
return concatenated.filter( ( item, pos ) => concatenated.indexOf( item ) === pos );
};
// example
[ 'a', 'b', 'c' ].union([ 'b', 'c', 'd', 'e' ]); // [ 'a', 'b', 'c', 'd', 'e' ]