Javascript Node JS,传统数据结构?(例如 Set 等),诸如 Java.util 之类的用于 node 的东西?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12204472/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Node JS, traditional data structures? (such as Set, etc), anything like Java.util for node?
提问by Rick
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.
我喜欢 node JS,并且来自 Java 背景,我什至有兴趣将它用于一些 node 可能看起来有点牵强的项目,例如搜索引擎项目。
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.
我有点困惑的一件事是 JavaScript 似乎缺乏传统的数据结构,例如集合,它的精确定义甚至超出了计算机科学,因为它在计算机出现之前就已用于数学中(基本上是一个列表不允许重复)。似乎在使用 node JS 时,没有像 Java.util 这样的库具有我已经习惯的这些基本数据类型,我意识到我可以自己创建它们,但这只会给项目增加更多的开销。
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.
是否有任何用于解决此问题的节点(或一般的 JavaScript)库?我认为 node 有很大的潜力在很多项目中取代 Java 等语言的使用,因为它在开发速度方面有很多优势,但必须重新创建在更成熟的平台上理所当然的数据结构对于一个小项目来说,开销可能太大。
I apologize if there are other questions like this, however I spent some time searching and didn't come up with much.
如果还有其他类似的问题,我深表歉意,但是我花了一些时间进行搜索并没有想出太多。
采纳答案by Hector Correa
Have you looked into Underscore.js? http://underscorejs.org/
你看过 Underscore.js 吗?http://underscorejs.org/
It's not a one to one with java.util but it provides a bunch of commonly needed utility functions.
它不是与 java.util 一对一的,但它提供了一堆常用的实用程序函数。
回答by Adrian Macneil
es6 has a Set class built in:
es6 内置了一个 Set 类:
new Set([iterable]);
see: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set
请参阅:https: //developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set
回答by weiyin
Collections.jshas Lists, Maps, Queues, Sets, and Heaps, all with consistent interfaces. Github.
Collections.js有 Lists、Maps、Queues、Sets 和 Heaps,它们都有一致的接口。GitHub。
回答by B T
Its no longer true that node.js doesn't have Set
and Map
objects among other things. node.js has had them since at latest v12.
node.js 没有Set
和Map
对象等不再是真的。node.js 从最新的 v12 开始就有了它们。
But of course, if you want libraries like java has, check npm or github. You're not limited to what comes standard in node.js.
但当然,如果你想要像 java 这样的库,请检查 npm 或 github。您不仅限于 node.js 中的标准内容。
回答by Gates VP
it seems JavaScript is lacking traditional data structures...
似乎 JavaScript 缺乏传统的数据结构......
Yes, this is javascript, the very concept and implementation of data structure is done quite differently from languages like Java.
是的,这是 javascript,数据结构的概念和实现与 Java 等语言完全不同。
I'm not sure that you're really going to find what you're looking for with Javascript. Howver, there are some libraries like underscore
that should make it easier to build the type of structures that you want.
我不确定您是否真的会使用 Javascript 找到您想要的东西。但是,有一些类似的库underscore
应该可以更轻松地构建您想要的结构类型。
回答by davidbourguignon
As a lighter and faster alternative to Underscore.js, Lo-Dash (http://lodash.com/) is getting traction those days... But this is not Java.util! :-)
作为 Underscore.js 的更轻、更快的替代品,Lo-Dash ( http://lodash.com/) 那些日子越来越受欢迎......但这不是 Java.util!:-)
回答by Jan ?wi?cki
Something like this: https://github.com/PeterScott/simplesets-nodejs, but with other datastructures?
像这样:https://github.com/PeterScott/simplesets-nodejs,但还有其他数据结构?
回答by Mathieu M-Gosselin
Have a look at this one: https://github.com/chenglou/data-structures
看看这个:https: //github.com/chenglou/data-structures
I think it fits what you are looking for.
我认为它适合你正在寻找的东西。
回答by factotum
I understand that this thread is old but wanted to chime in for future reference and for folks arriving here via web search. I have been building a Node.js library precisely to address non-availability of standard data structures in JavaScript, similar to Java collections. Its available here - https://github.com/monmohan/dsjslib.
我知道这个帖子很旧,但想加入以供将来参考和通过网络搜索到达这里的人们。我一直在构建一个 Node.js 库,正是为了解决 JavaScript 中标准数据结构的不可用问题,类似于 Java 集合。它在这里可用 - https://github.com/monmohan/dsjslib。
contributors are welcome :)
欢迎贡献者:)