Created
October 13, 2017 14:39
-
-
Save qwtel/c5fa834d0aec8caf248c9b0578e0a250 to your computer and use it in GitHub Desktop.
Quick-and-Dirty `Set` implementation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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