3 ms·
The lack of sets as a data type at the language level is a serious problem with JS. Most languages which implement sets as a library make some assumption about
by pjscott 16y ago
The lack of sets as a data type at the language level is a serious problem with JS. Most languages which implement sets as a library make some assumption about the elements: they're ordered, for example, or they all have a unique string serialization. If you want to make a set data type in JavaScript, the language doesn't give you any of those assumptions. You might end up just using linear search of unordered arrays. (This is actually very fast for small sets, but still.)
I wrote some more about this here:
http://finger-tree.blogspot.com/2010/09/sets-in-javascript.html http://finger-tree.blogspot.com/2010/09/sets-in-javascript.h...
And here is a library that offers sets in JS:
http://github.com/PeterScott/simplesets-nodejs http://github.com/PeterScott/simplesets-nodejs
If you're using Node.js, you can get it with npm. It could be adapted to the browser pretty easily. This is what I use, and it makes my life so much easier.