Linked Questions
27 questions linked to/from Javascript ES6 computational/time complexity of collections
38
votes
2
answers
27k
views
Is the Set.has() method O(1) and Array.indexOf O(n)? [duplicate]
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....
3
votes
1
answer
4k
views
Time complexity of Set and Map in javascript [duplicate]
What is time complexity of basic operation in Set & Map in javascript?
Are they in hashmaps or BSTs?
0
votes
1
answer
2k
views
Big O and sets in Javascript [duplicate]
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......
0
votes
0
answers
1k
views
What are the big O notation of Javascript's Map.prototype.has and Set.prototype.has methods? [duplicate]
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. ...
0
votes
1
answer
63
views
Which search algorithm does Map.prototype.has use internally? [duplicate]
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
0
votes
0
answers
62
views
Efficiency of Checking if an Item exists in Set (Javascript) [duplicate]
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.
0
votes
0
answers
25
views
Time complexity (Big O) for JavaScript Set [duplicate]
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 ...
218
votes
16
answers
226k
views
Check variable equality against a list of values
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 ...
84
votes
5
answers
46k
views
es6 Map and Set complexity, v8 implementation
Is it a fair assumption that in v8 implementation retrieval / lookup is O(1)?
(I know that the standard doesn't guarantee that)
78
votes
2
answers
21k
views
ES6: Is it dangerous to delete elements from Set/Map during Set/Map iteration?
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 ...
69
votes
3
answers
67k
views
What is the time complexity of javascript's array.indexOf?
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?
11
votes
1
answer
7k
views
Why "Map" manipulation is much slower than "Object" in JavaScript (v8) for integer keys?
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 ...
12
votes
3
answers
2k
views
Do Javascript Maps have a set amount of keys that they can set or do they have a set amount of key operations that can be done?
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 ...
8
votes
2
answers
6k
views
Set lookup time slower than Object?
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 ...
6
votes
1
answer
3k
views
Is there anything that guarantees constant time for accessing a property of an object in JavaScript?
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 ...