JSFunctions Flashcards
Remembering common JS Functions
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
- map.set(key,value)
- map.delete(key)
- map.has(key)
- map.get(key)
- map.keys()
- map.values()
- map.size
What is the time complexity of find()
O(n)
What is the time complexity of findIndex()
O(n)
What is the time complexity of sort()
Can depend on the browser, but O(n log n)
What is the time complexity of splice()
O(n)
What is the time complexity of slice()
O(n)
What is the difference between slice() and splice()?
slice() returns a copy of the portion of an array into a new object. splice() is used to modify an array in place
[Slice]Given a list like [‘a’,’b’,’c’,’d’], what would the following do
list.slice(2) list.slice(1,2)
list.slice(2) // returns ['c','d'] list.slice(1,2) // returns['b','c']