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...

КОМЕНТАРІ • 19

  • @jamster0777
    @jamster0777 7 років тому +8

    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!

  • @MrRight1000
    @MrRight1000 6 років тому +3

    Correction @ 4:28
    map.entries() - returns keys + entries
    map.keys() - returns keys

  • @crashito_x
    @crashito_x 4 роки тому +1

    Man you are amazing at explaining this stuff

  • @goodwish1543
    @goodwish1543 7 років тому +4

    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. ;)

    • @andrewspode
      @andrewspode 6 років тому

      Nothing a quick check wouldn't solve - but agreed - it stuck out at me too!

  • @sassmailsas
    @sassmailsas 6 років тому +1

    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}

  • @core_dump
    @core_dump 6 років тому

    Maps are useful for practical programming and Competitive programming alike.

  • @admiralrohan
    @admiralrohan 7 років тому

    I am facing problems for using these new syntax of ES6... can't remember syntax at the time of programming... what to do?

  • @grantpant2353
    @grantpant2353 5 років тому

    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?

    • @stogenzzo
      @stogenzzo 5 років тому +2

      i think its speeded up, look at text marker blinking speed

  • @TonyJPG
    @TonyJPG 7 років тому

    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?

    • @BeauCarnes
      @BeauCarnes 7 років тому +1

      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.

    • @TonyJPG
      @TonyJPG 7 років тому

      I see, that makes sense. Thanks for answering!
      Great videos btw, I'm learning a lot.

    • @evgeniiserebriakov9539
      @evgeniiserebriakov9539 7 років тому +1

      You should use 'var count' instead this.count.
      In other case someone can change the count value using 'map.count = 150;', for example.

  • @Jordanistheonlyholywaterriver

    Watch 2x speed but we about 40-50 videos a week.

  • @anantvarma6762
    @anantvarma6762 3 роки тому

    Couldn't understand a single thing after watching it thrice. Rushing through the code without explaining anything. By far the worst explanation.

  • @sethkoch7441
    @sethkoch7441 6 років тому

    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.

    • @freecodecamp
      @freecodecamp  6 років тому +9

      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".

    • @NhonHa
      @NhonHa 5 років тому +6

      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.