Skip to content

Instantly share code, notes, and snippets.

@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' ]
function walkDOMTree(
root,
whatToShow = NodeFilter.SHOW_ALL,
{ inspect, collect, callback } = {}
) {
const walker = document.createTreeWalker(root, whatToShow, {
acceptNode(node) {
if (inspect && !inspect(node)) {
return NodeFilter.FILTER_REJECT;
}