JSFunctions Flashcards

Remembering common JS Functions

1
Q

Map Methods

Using a Map, what functions would you need to:
1. Add something
2. Remove a value
3. Check if a key exists
4. Get an item by its key
5. Get all the items
6. Get all the key names
7. Get the length

A
  1. map.set(key,value)
  2. map.delete(key)
  3. map.has(key)
  4. map.get(key)
  5. map.keys()
  6. map.values()
  7. map.size
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the time complexity of find()

A

O(n)

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

What is the time complexity of findIndex()

A

O(n)

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

What is the time complexity of sort()

A

Can depend on the browser, but O(n log n)

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

What is the time complexity of splice()

A

O(n)

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

What is the time complexity of slice()

A

O(n)

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

What is the difference between slice() and splice()?

A

slice() returns a copy of the portion of an array into a new object. splice() is used to modify an array in place

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

[Slice]Given a list like [‘a’,’b’,’c’,’d’], what would the following do

 list.slice(2) 
list.slice(1,2) 
A
 list.slice(2) // returns ['c','d'] 
list.slice(1,2) // returns['b','c'] 
How well did you know this?
1
Not at all
2
3
4
5
Perfectly