OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

What is the fastest or most elegant way to compute a set difference using Javascript arrays?

  • Thread starter Thread starter Matt Ball
  • Start date Start date
M

Matt Ball

Guest
Let A and B be two sets. I'm looking for really fast or elegant ways to compute the set difference (A - B or A \B, depending on your preference) between them. The two sets are stored and manipulated as Javascript arrays, as the title says.

Notes:

  • Gecko-specific tricks are okay
  • I'd prefer sticking to native functions (but I am open to a lightweight library if it's way faster)
  • I've seen, but not tested, JS.Set (see previous point)

Edit: I noticed a comment about sets containing duplicate elements. When I say "set" I'm referring to the mathematical definition, which means (among other things) that they do not contain duplicate elements.

<p>Let <code>A</code> and <code>B</code> be two sets. I'm looking for <em>really</em> fast or elegant ways to compute the set difference (<code>A - B</code> or <code>A \B</code>, depending on your preference) between them. The two sets are stored and manipulated as Javascript arrays, as the title says.</p>

<p>Notes:</p>

<ul>
<li>Gecko-specific tricks are okay</li>
<li>I'd prefer sticking to native functions (but I am open to a lightweight library if it's way faster)</li>
<li>I've seen, but not tested, <a href="http://jsclass.jcoglan.com/set.html" rel="noreferrer">JS.Set</a> (see previous point)</li>
</ul>

<p><strong>Edit:</strong> I noticed a comment about sets containing duplicate elements. When I say "set" I'm referring to the mathematical definition, which means (among other things) that they do not contain duplicate elements.</p>
 

Latest posts

H
Replies
0
Views
1
haifisch123
H
A
Replies
0
Views
1
Adrian-Mihai Enache
A
H
Replies
0
Views
1
Hür Doğan ÜNLÜ
H
Top