473,396 Members | 1,864 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to implement collections (Set, List, Map) in JavaScript ?

Hej everybody.

I am writing a lot of code in JavaScript, and my code begins too look
to complicated... My work would be more effective is i could somehow
emulate Sets, Lists and Maps especially some of its operations.

Set - A collection that contains no duplicate elements (and its
elements may be everything: strings, function references, DOM element
references etc.);

List - An ordered collection (also known as a sequence) (and again
its elements may be everything: strings, function references, DOM
element references etc.);

Map - An object that maps keys to values. A map cannot contain
duplicate keys; each key can map to at most one value;

Can anyone point me to relevant URL's ? I know it is a lot to ask at
one post, but any clues would help.

B.R.
Luke Matuszewski.

Mar 3 '06 #1
1 11134
Luke Matuszewski wrote:
I am writing a lot of code in JavaScript, and my code begins too look
to complicated... My work would be more effective is i could somehow
emulate Sets, Lists and Maps especially some of its operations.

Set - A collection that contains no duplicate elements (and its
elements may be everything: strings, function references, DOM element
references etc.);
You are looking for any native ECMAScript object or a user-defined object
derived from it. You will need a setter, maybe using a hash function
applied on elements to be added to compute the respective property name,
to make sure no duplicate can be created within the data structure.
List - An ordered collection (also known as a sequence) (and again
its elements may be everything: strings, function references, DOM
element references etc.);
You are looking for Array objects, or any native ECMAScript object or a
user-defined object derived from it that refers to Array objects with
one of its properties. You will have to define a getter that considers
elements with a special value (for example `undefined') as an indicator
that the next/previous "list element" should be accessed instead.
Map - An object that maps keys to values. A map cannot contain
duplicate keys; each key can map to at most one value;


You are looking for any native ECMAScript object, or a user-defined object
derived from it.

In all cases, unless said otherwise, I recommend to use Object objects as
prototype, because they provide the least number of built-in properties,
which minimizes the risk of a property name collision and the size of the
memory footprint of the user-defined object.

<URL:http://pointedears.de/scripts/collection.js> maybe helps you to
implement this.
PointedEars
Mar 3 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Atley | last post by:
I am trying to set up a nested collection so I can run statements like this: me.lblquestions.text = mysteps.item(1).questions(1).Asked Any ideas on how to do this? I have created a...
7
by: Bmack500 | last post by:
I'm definitely doing something wrong here. I have a class called Servers, implemented as below. I then create my collection as below. Then, I'll add a server object to the collection as follows: ...
17
by: nicolas.hilaire | last post by:
Hi all, i'm doing a quite long treatment in a function, and i'm showing the progress of the treatment with a progressbar. The code is something like this : for each(entry in entries) // about...
6
by: Arthur Dent | last post by:
How do you sort a generic collection derived from System.Collections.ObjectModel.Collection? Thanks in advance, - Arthur Dent
2
by: Lucian Wischik | last post by:
Does ReadOnlyCollection<T> really implement IList<T>, like it claims to do? ... When I right-click on ReadOnlyCollection and look at its definition, it says this: public class...
5
by: junw2000 | last post by:
When should I use each of these three containers? What is the difference? For list and vector, it is obvious. How about set and map? Thanks a lot.
4
by: PenguinPig | last post by:
Dear Experts, Could you please provide you comment to me? Thanks An Exhibition has many Halls, and different Booth Types If exhibition is not exist, hall and booth type will not exist too. ...
3
by: Godspeed | last post by:
I have started writing a new collections library based on set theory as per Spivey's Z notation. I have put the library on SourceForge. It is currently in its infancy and it will be expanded fairly...
2
by: Tony Johansson | last post by:
Hello! Below I have a working program. I have one generic class called Farm<T> with this header definition public class Farm<T: IEnumerable<Twhere T : Animal Now to my question I changed the...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.