Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node JS, traditional data structures? (such as Set, etc), anything like Java.util for node?

Tags:

I'm loving node JS and, coming from a Java background, am interested in even trying it out for some projects where node may seem a bit of a stretch, such as a search engine project.

One thing I've been a bit confused by is it seems JavaScript is lacking traditional data structures, for example a set, which has a precise definition extending even beyond computer science as it has been used in mathematics before computers existed (basically a list that doesn't allow duplicates). It seems when using node JS there is no library like Java.util that has these basic data types that I have grown accustomed to, I realize I could create them myself but this just adds more overhead to the project.

Are there any libs for node (or JavaScript in general) that address this? I think node has a lot of potential to replace the use of a language like Java for a lot of projects as it has so many advantages in terms of development speed, but having to recreate data structures that are taken for granted in a more mature platform could be too much overhead for a small project.

I apologize if there are other questions like this, however I spent some time searching and didn't come up with much.

like image 260
Rick Avatar asked Aug 30 '12 19:08

Rick


2 Answers

es6 has a Set class built in:

new Set([iterable]); 

see: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set

like image 63
Adrian Macneil Avatar answered Nov 02 '22 23:11

Adrian Macneil


Collections.js has Lists, Maps, Queues, Sets, and Heaps, all with consistent interfaces. Github.

like image 26
weiyin Avatar answered Nov 02 '22 23:11

weiyin