Quick and Dirty Set
A tiny (10 LOC) ES6 Set
implementation.
Think of it as a forwards-compatible _.uniq(array)
.
Disclaimer: Not a complete polyfill, don't use on large data.
Usage
; const s = 1 2 2 3ssize // => 3s // => Set([1, 2, 3])s // => Set([1, 2, 3, 4])s // => trues // => 3s// 1// 2// 4sclear ssize // => 0s // => false
Need keys
, values
, entries
?
; const s = 1 2 2 3const it = s;itnextvalue // => 1itnextvalue // => 2itnextvalue // => 3itnextdone // => true
Source
{ a = a; asize = alength; a a > -1; a { if !a asize++; a; return a; }; a { let t; if t = a asize--; a return t; }; a { while a {} asize = 0; }; return a;}