Skip to content

Instantly share code, notes, and snippets.

@qwtel
Created October 13, 2017 14:39
Show Gist options
  • Save qwtel/c5fa834d0aec8caf248c9b0578e0a250 to your computer and use it in GitHub Desktop.
Save qwtel/c5fa834d0aec8caf248c9b0578e0a250 to your computer and use it in GitHub Desktop.
Quick-and-Dirty `Set` implementation
// Quick-and-Dirty `Set` implementation.
/* eslint-disable */
export const Set = global.Set || function (a = []) {
a = a.filter((x, i) => i === a.indexOf(x));
a.size = a.length;
a.has = x => a.indexOf(x) > -1;
a.add = x => { if (!a.has(x)) { a.size++; a.push(x); } return a; };
a.delete = x => { let t; if (t = a.has(x)) { a.size--; delete a[a.indexOf(x)]; } return t; };
a.keys = a.values = () => a[Symbol.iterator]();
a.clear = () => { while (a.pop()) {} a.size = 0; };
return a;
};
/* eslint-enable */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment