Linked Questions

38 votes
2 answers
27k views

I have seen in an answer that the Set.has() method is O(1) and Array.indexOf() is O(n). var a = [1, 2, 3, 4, 5]; a.indexOf(5); s = new Set(a); s.has(5); //Is this O(1)? Is Set....
Charlie's user avatar
  • 24k
3 votes
1 answer
4k views

What is time complexity of basic operation in Set & Map in javascript? Are they in hashmaps or BSTs?
Jeong Ho Nam's user avatar
0 votes
1 answer
2k views

What are the Big-O notations for Sets in Javascript? Is it always faster than an array? Additionally, can you tell me where I should be looking here for sets? (i.e. what category does it fall under......
dlearns's user avatar
  • 81
0 votes
0 answers
1k views

What are the big O notations of Javascripts Map.prototype.has and Set.prototype.has methods? According to the documentation for Set: The following steps are taken: Let S be the this value. ...
user3554664's user avatar
0 votes
1 answer
63 views

This method is relatively fast and I was wondering which search algorithm does it implement internally. I had a look in the ECMASCript spec but it wasn't very enlightening: Map.prototype.has
Michael K's user avatar
  • 373
0 votes
0 answers
62 views

I was wondering how the new Set data structure is implemented in Javascript. In particular, what would be the Big O efficiency inserting, deleting, or checking if an item exists in a set.
Shawn123's user avatar
  • 457
0 votes
0 answers
25 views

We can find unique elements of array using JavaScript Set(). You can create a set by either giving array initially or use Set.prototype.add(). What are time complexities and space complexities for ...
Salitha's user avatar
  • 1,177
218 votes
16 answers
226k views

I'm checking a variable, say foo, for equality to a number of values. For example, if( foo == 1 || foo == 3 || foo == 12 ) { // ... } The point is that it is rather much code for such a trivial ...
pimvdb's user avatar
  • 155k
84 votes
5 answers
46k views

Is it a fair assumption that in v8 implementation retrieval / lookup is O(1)? (I know that the standard doesn't guarantee that)
Uri's user avatar
  • 27.1k
78 votes
2 answers
21k views

Safe code for new Set() may look like: let items = []; for (let item of set) if (isBad(item)) items.push(item); for (let item of items) set.delete(item) Can I simplify code to: for (let item ...
gavenkoa's user avatar
  • 49.6k
69 votes
3 answers
67k views

Does indexOf simply walk through the array or does it do something that is faster? I know that this is implementation dependent but what does Chrome or Firefox do?
user1056805's user avatar
  • 2,963
11 votes
1 answer
7k views

I was happily using Map for indexed accessed everywhere in my JavaScript codebase, but I've just stumbled upon this benchmark: https://stackoverflow.com/a/54385459/365104 I've re-created it here as ...
CanonicEpicure's user avatar
12 votes
3 answers
2k views

So I know that Javascript Maps have a set amount of keys that they can store ( around 16.7 M ). I was trying to test if I can ( in a very ugly way ) remove the oldest elements from the array. I ...
stefantigro's user avatar
8 votes
2 answers
6k views

Out of curiousity, I decided to confirm my belief that the Set implementation is faster than Object (running in google chrome) in terms of insertion/addition and lookup. My results were slightly ...
Chad Pendergast's user avatar
6 votes
1 answer
3k views

This is in regards to a debate I had with an interviewer when I was interviewing at Amazon. Let's I create an object: var Obj = {}; Obj['SomeProperty'] = function ( ) { console.log("Accessed some ...
user5648283's user avatar
  • 6,253

15 30 50 per page