- Explain what a data structure is
- Use JavaScripts Map data structure
- Use JavaScripts Set data structure
- Build a custom data structure
-
Turn to your neighbor and discuss what a data structure is in your own words.
Your answer...
-
What are some examples of data structures we've used in JavaScript?
Your answer...
Take a look at the new Map
data structure
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map
const obj = {}
obj.name = 'Rocko' // set key & value
obj.name // returns value 'Rocko'
const map = new Map()
map.set('name', 'Rocko') // set key & value
map.get('name') // returns value 'Rocko'
map.size // counts key-value pairs
https://repl.it/@galvanize/MapExample
Take a look at the new Set
data structure
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set
How does a set differ from a Map?
const s = new Set()
s.add('Rocko') // adds item to set
s.add('Spunky')
s.add('Rocko') // does NOT add duplicate item
s.size() // counts items in set
https://repl.it/@scottyhurlow/SetExample
Take a look at the following repo: CustomSet.
Fork & clone the repo. Follow the tests to implement the CustomSet data structure.