Objects, Arrays - Analyzing Performance Flashcards

1
Q

Objects - Insertion

A

O(1)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Objects - Removal

A

O(1)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Objects - Searching

A

O(n)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Objects - Access

A

O(1)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Object.keys

A

O(n)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Object.values

A

O(n)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Object.entries

A

O(n)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

hasOwnProperty

A

O(1)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Arrays - Insertion

A

It depends (unless array is empty then same):

  • push : O(1)
  • unshift: O(n) *need to reindex every item after
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Arrays - Removal

A

It depends (unless array is empty then same):

  • pop: O(1)
  • shift: O(n) *needs to reindex following items
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Arrays - Searching

A

O(n)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Arrays - Access

A

O(1)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

concat

A

O(n)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

slice

A

O(n)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

splice

A

O(n)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

sort

A

O(n * log n) - larger than O(n) because need to make comparisons, move things around

17
Q

forEach/map/filter/reduce

A

O(n) - looping over each element and doing something specific to it