Skip to content

Instantly share code, notes, and snippets.

@bendc
Created July 31, 2015 00:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bendc/1ff4c9639b21f1ad735f to your computer and use it in GitHub Desktop.
Save bendc/1ff4c9639b21f1ad735f to your computer and use it in GitHub Desktop.
Cross-browser cloneSet function
const cloneSet = (() =>
new Set(new Set().add(1)).has(1)
? set => new Set(set)
: set => {
const clone = new Set();
set.forEach(item => clone.add(item));
return clone;
})();
@bendc
Copy link
Author

bendc commented Jul 31, 2015

const foo = new Set().add("foo");
const bar = cloneSet(foo).add("bar");
bar.size; // => 2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment