Map data structure & ES6 map object - Beau teaches JavaScript
Вставка
- Опубліковано 13 жов 2024
- Maps are data structures that store key-value pairs. See how they work and learn about the ES6 map object.
💻 Code: codepen.io/beau...
🔗 Info: developer.mozi...
🐦 Beau Carnes on Twitter: / carnesbeau
⭐JavaScript Playlists⭐
▶JavaScript Basics: • JavaScript Basics Course
▶Data Structures and Algorithms: • Data Structures and Al...
▶Design Patterns: • Design Patterns - Beau...
▶ES6: • ES6 - Beau teaches Jav...
▶Clean Code: • Clean Code - Beau teac...
-
We're busy people who learn to code, then practice by building projects for nonprofits. Learn Full-stack JavaScript, build a portfolio, and get great references with our open source community.
Join our community at freecodecamp.com
Read great tech articles at medium.freecod...
These tutorials are excellent! The length is perfect and seeing a new concept or an old one in a different context is so useful. Thanks!
Correction @ 4:28
map.entries() - returns keys + entries
map.keys() - returns keys
Man you are amazing at explaining this stuff
Very good explanation. Thank you teacher.
There might be one issue. It is the count++ in set method.
If we add item with existing key, it should not increment the count.
My CA$ 0.02. ;)
Nothing a quick check wouldn't solve - but agreed - it stuck out at me too!
So, the benefit of Map is that you can use key not only String or Symbol. But in your example you use Object as as collection to store key:value. It's wrong implementation. You need to use array as collection with item {key: key, value: value}
Maps are useful for practical programming and Competitive programming alike.
I am facing problems for using these new syntax of ES6... can't remember syntax at the time of programming... what to do?
Your typing speed literally makes my head spin. I don't think I can even make my fingers moves that fast. You're an android, aren't you?
i think its speeded up, look at text marker blinking speed
Hello, why do you make a size function (the one that returns the variable count), can't you just call the variable count directly?
don't myObj.count and myObj.size() return the same value?
Yes, they do return the same value. There are two reasons for the size function. The main one is so you can use the terminology generally associated with maps. (which is 'size') Also, as a general practice, it is good to access variables stored in an object through functions. This allows you to make easier changes in the future to how the value is calculated or possibly only return the variable if certain conditions are met.
I see, that makes sense. Thanks for answering!
Great videos btw, I'm learning a lot.
You should use 'var count' instead this.count.
In other case someone can change the count value using 'map.count = 150;', for example.
Watch 2x speed but we about 40-50 videos a week.
Couldn't understand a single thing after watching it thrice. Rushing through the code without explaining anything. By far the worst explanation.
This is entirely incorrect. A map is not a javascript object. You would not, for example, be able to use a function as a key in your implementation. This is a very naive and very wrong tutorial. You should take this video down.
Good point about not being able to use a function as a key. However, you are incorrect to say 'a map is not a javascript object'. A map is a JavaScript Object. To prove it, try running this JavaScript code: `var m = new Map(); m instanceof Object` and you will see that a map is technically an object. Also, according to MDN, historically in JavaScript, "Objects have been used as Maps".
Someone does a video to explain how to use map. Someone complains the definition is wrong and video should be taken down. Point of the video is how to use map, not the definition of a map! This video is legit.