How to Implement a Hash Table in JavaScript

แชร์
ฝัง

ความคิดเห็น • 179

  • @Akshatgiri
    @Akshatgiri 4 ปีที่แล้ว +97

    I was asked to create a hash table ( in js ) from scratch in an interview and I bombed it. Thanks for the vid. 👍

    • @ben790924
      @ben790924 3 ปีที่แล้ว +4

      It had to be Google、Facebook、Amazon interview i guess XD

    • @MrPaulsonantajo
      @MrPaulsonantajo 3 ปีที่แล้ว +13

      Some non-JS developer comes as a JS interviewer and ask all these questions about the hash map and hash table and create a big deal out of it. Basically, the JS object serves the purpose of the hash table and there is a high chance that most of the JS developers never heard about the hash map.

    • @vivekgoswami1474
      @vivekgoswami1474 2 ปีที่แล้ว

      Really bro

  • @kzakaria91
    @kzakaria91 4 ปีที่แล้ว +185

    i actually like this kind of videos more than frameworks, being self taught always feels like im missing on cs fundamentals even though i can set up graphql with the newest hip frontend framework LOL.
    keep em coming ben, appreciate the great work

  • @hnasr
    @hnasr 4 ปีที่แล้ว +51

    I like your videos Ben, unique content and always questioning how things are made.

  • @stephenyin3509
    @stephenyin3509 4 ปีที่แล้ว +7

    Amazing video! I use dict/object/hashtable a lot in my daily programming, but never have a thought how it works. This video just gives me a great intro of the principle behind the hashtable under the hood! Keep working Ben! You should deserved to have millions of subscribers!

  • @lsamax4468
    @lsamax4468 4 ปีที่แล้ว +44

    when you call a setItem again with same key, the output will like as [[["firstName", "bob"], ["firstName", "sam"]]],
    after that, you call the getItem will get "bob", cus you just return the first element in table.
    so, you need to adjust the setItem method as below (O(n)):
    if (this.table[idx]) {
    const item = this.table[idx].find(x => x[0] === key);
    if (item) {
    item[1] = value;
    } else {
    this.table[idx].push([key, value]);
    }
    } else {
    this.table[idx] = [[key, value]];
    }

    • @ErikBongers
      @ErikBongers 4 ปีที่แล้ว

      Jep. Been couple of weeks now, and not too many people who noticed this, it seems.

    • @bawad
      @bawad  4 ปีที่แล้ว +9

      Good catch idk how I forgot about this

  • @nstwin9
    @nstwin9 4 ปีที่แล้ว +14

    Yessss! More data structures and algorithm videos please 🙏🙏🙏🙏🙏🙏🙏🙏🙏

  • @sbrugby1
    @sbrugby1 4 ปีที่แล้ว +8

    great tip on Quokka. It feels like a jupyter notebook or something for js in vscode. I'm loving it.

  • @purdysanchez
    @purdysanchez 4 ปีที่แล้ว +9

    Great job on a sample implementation of a hashtable in JS!

  • @Jason_Lucero
    @Jason_Lucero 3 ปีที่แล้ว +4

    Damn ben, never really watched you for your tutorials but damn, this was clean

  • @lukehatcher98
    @lukehatcher98 3 ปีที่แล้ว +1

    Great video. I implemented a bottom threshold where if the table is less than .25% full, create a new table of half the length and rehash

  • @MachiriReviews
    @MachiriReviews ปีที่แล้ว

    This is a really good guide. From this I was also able to write a function that reassigns values.

  • @OfferoC
    @OfferoC 4 ปีที่แล้ว +1

    Great video, thanks. I would love a video comparing different hash functions.

  • @juanmarino1186
    @juanmarino1186 ปีที่แล้ว

    watching you code is fun

  • @Sinan997
    @Sinan997 ปีที่แล้ว

    dude this is golden, appreciated that

  • @mohamedaljamil6334
    @mohamedaljamil6334 4 ปีที่แล้ว +2

    I finally understood hash tables. thank you

  • @theemacsen1518
    @theemacsen1518 4 ปีที่แล้ว +1

    Great video as always Ben!!

  • @IlhanNegis
    @IlhanNegis 4 ปีที่แล้ว +6

    very nice one, funfact, in js actually object is base, array is derived from object, so actually arrays are hashmap with number keys.

    • @bawad
      @bawad  4 ปีที่แล้ว

      oh really, that's interesting, so how does the object work underneath?

    • @IlhanNegis
      @IlhanNegis 4 ปีที่แล้ว

      that I'm not sure, but all bit at the metal. but on language itself the base is object, do not quote me but firefox engine has a native array implementation for performance afaik.

    • @mzcustom2
      @mzcustom2 4 ปีที่แล้ว +2

      Entering typeof([ ]) in the console of all my browsers confirms your claim. Have been using the object as hashtable in Javascript since day one and never felt the necessity of the implementing one. I believe the dense array is the way to go when possible cuz it's just a wrapper for a C array.

    • @alexnezhynsky9707
      @alexnezhynsky9707 4 ปีที่แล้ว

      Pretty sure object derives from an array, and all arrays are actually fixed in size, so the object just computes indexes with a hash function

    • @nekran
      @nekran 4 ปีที่แล้ว

      In others langages(like java): object use hash table internally but with the V8 engine it use another technique. And for optimization purpose object are transformed in array (pre "turbofan" at least, not sure with the new "turbofan" compiler)

  • @ditoorkodashvili6018
    @ditoorkodashvili6018 3 ปีที่แล้ว +2

    Correct me if I am wrong but the way the setItem is implemented you may get a duplicate keys, because you are not replacing a pair if the key already exists in the array.

  • @fezekileplaatyi7224
    @fezekileplaatyi7224 3 ปีที่แล้ว +7

    Hey Ben, do you have other tutorials for other Data Structures? Man you explained this very nicely and easily

  • @riexrickgaming
    @riexrickgaming 3 ปีที่แล้ว

    do we need to create this hashtable implementation on our own or there is efficient library/ implementatiom existed already? just want to know the best practices

  • @MrREALball
    @MrREALball 4 ปีที่แล้ว +12

    2001 isnt prime, cuz 2+0+0+1 % 3 = 0, so u could divide it by 3

  • @anantsharma9806
    @anantsharma9806 3 ปีที่แล้ว

    In this implementation, we used an array to generate a hash value, so our performance is directly proportional to the length of key name we chose?

  • @tajpouria
    @tajpouria 4 ปีที่แล้ว +30

    I suggest you to make a series about functional programming pattern in TS/JS. That's one of the most popular concepts that's not any proper content on TH-cam about it, best regards...

  • @YaohanChen
    @YaohanChen 4 ปีที่แล้ว +5

    One way to simplify resize() is to just save the current table in a variable, assign this.table to the resized one, and then call setItem() for all the pairs in the old table.

    • @OfferoC
      @OfferoC 4 ปีที่แล้ว +1

      need to be careful about recursion in that case

  • @Jun-zq3bn
    @Jun-zq3bn 3 ปีที่แล้ว

    what extension or shortcut did you use to auto input ;

  • @godnessy
    @godnessy 2 ปีที่แล้ว

    Very cool video, thanks!

  • @jasonjones5079
    @jasonjones5079 4 ปีที่แล้ว +2

    Really enjoyed this!

  • @paco3447
    @paco3447 4 ปีที่แล้ว +5

    Good. But keep in mind that Hash tables despite perform fast with insertion, deletion and fetching, are really bad for searching wise operations, in the later case is better to use binary search tree structures.
    Other issue that comes to mind is that choosing odd primes for multiplier, in order to reduce collisions, are better suited for English words as is empirically taken with that language in mind.

  • @yaboiickydick9456
    @yaboiickydick9456 ปีที่แล้ว

    At 19:50, why did you change to foreach instead of using a for loop? Was it for readability, or is there a deeper reason for this choice?

  • @ltserge3226
    @ltserge3226 2 ปีที่แล้ว

    at 20:40 what command did you do to copy the line like that?

  • @hugothms
    @hugothms 3 ปีที่แล้ว

    That's very clear ! Thanks buddy

  • @claydaman22
    @claydaman22 4 ปีที่แล้ว +2

    This is cool and all but how would you use this in a real word app? Would I persist this to a DB?

  • @lucasdelbel7376
    @lucasdelbel7376 3 ปีที่แล้ว

    Awesome video.Thank you so much.

  • @hanifabeg1699
    @hanifabeg1699 3 ปีที่แล้ว

    which extension is he using for this auto onscreen console

  • @brNoMundo123
    @brNoMundo123 2 ปีที่แล้ว

    Great video!

  • @JaspreetSingh-eq2yk
    @JaspreetSingh-eq2yk 4 ปีที่แล้ว +6

    Inside the loop in your hashStringtoInt function should it be hash += (13*hash*s.charCodeat(i))%tableSize ?? Your solution has hash = (....) instead of hash+= (.....)

    • @kjl3080
      @kjl3080 3 ปีที่แล้ว +2

      Yes, his bad, because rn it only hashes the last character

  • @joestrkr
    @joestrkr 4 ปีที่แล้ว +1

    Very cool stuff. Love your channel :)

    • @bawad
      @bawad  4 ปีที่แล้ว

      Thanks!

  • @adhupraba
    @adhupraba 3 ปีที่แล้ว

    great video... also what is your vs code's font name? I'd like to set for mine too...

  • @inasuma8180
    @inasuma8180 3 ปีที่แล้ว

    Is there a more optimized way to resize the hash table? 🤔

  • @khadijasheikh8144
    @khadijasheikh8144 2 ปีที่แล้ว

    Thank you so much this video is benefitfull i appreciate it .

  • @frankie_goestohollywood
    @frankie_goestohollywood 3 ปีที่แล้ว

    Thank you, Ben!!! :-)

  • @producdevity
    @producdevity 4 ปีที่แล้ว +2

    I love the explanation. It would be great if you could give an example where this would be useful , because I can’t come up with one by myself

    • @purdysanchez
      @purdysanchez 4 ปีที่แล้ว +2

      It's useful as a teaching example of a basic hashtable implementation

    • @spaghettiking653
      @spaghettiking653 3 ปีที่แล้ว +2

      What he said, because Objects in JS already do this by default and are faster than the manual implementation. This is just an example of how it works underneath the hood, which is very fascinating. Btw, this is probably way more useful in lower-level languages, especailly those without an existing hashmap object.

  • @ajaykrishnareddy
    @ajaykrishnareddy 4 ปีที่แล้ว

    Hi , I currently using react hooks is there any way that use call back after setting the state using useState hook

    • @bawad
      @bawad  4 ปีที่แล้ว

      what do you mean?

  • @SinanAkkoyun
    @SinanAkkoyun 3 ปีที่แล้ว

    How high is ur monitor?

  • @evanstapp
    @evanstapp 4 ปีที่แล้ว +1

    Good one Ben

  • @TadesseDev
    @TadesseDev 2 ปีที่แล้ว

    I am dancing now 😎, because I know the error that happens as you type it. 21:00, Great content buddy. Subscribed.

  • @28bits20
    @28bits20 4 ปีที่แล้ว +7

    Nice tutorial. One note though: at 12:24 you should’ve checked if(this.table[idx] === undefined) instead because if someone has set the value to 0 or an empty string it will not evaluate to true.

    • @bawad
      @bawad  4 ปีที่แล้ว +1

      good catch

    • @31redorange08
      @31redorange08 3 ปีที่แล้ว +1

      Bad catch. There will either be an array or undefined, never 0 or an empty string.

    • @28bits20
      @28bits20 3 ปีที่แล้ว

      redorange Check again. He is checking if the value is set for a given key. The value could be anything including 0 or an empty string not just an array or undefined.

    • @doodoostickstain
      @doodoostickstain 2 ปีที่แล้ว

      What's wrong with having a 0 or empty string? Maybe I'm mistaken for reasons, but if I stored a 0 or '', i'd prefer for someone to NOT overwrite it because they feel it shouldn't exist. can anyone explain? they're legal values, after all, though they may not make much sense without context. we should PROTECT our values :D not destroy them

    • @doodoostickstain
      @doodoostickstain 2 ปีที่แล้ว +4

      ok never mind I get it now, took a moment :D

  • @jmoo4457
    @jmoo4457 4 ปีที่แล้ว +4

    Small improvement suggestion. The `setItem` function should probably take into account of update on same key (i.e. when an item with the same key already exists). After that, `this.numItems++` should only happen when a new key is inserted. Otherwise we can do `setItem("sameKey",123)` multiple times and keep increasing the hash table when it doesn't need to be bigger.

    • @jmoo4457
      @jmoo4457 4 ปีที่แล้ว

      Another improvement is to use a linked list instead of a generic array for the "bucket" in each indices. This will become useful when there is a need to delete items from the hashmap (which wasn't part of this implementation), since linked-list deletion is O(1).

    • @jmoo4457
      @jmoo4457 4 ปีที่แล้ว +1

      I want to point out that this was an excellent intro to hash tables by Ben Awad, and he implemented one of the solutions for hash collision (Separate Chaining), but there are other strategies that can be used. I found GeeksForGeeks Hashing Set 1~3 videos helpful for learning about different strategies if you are curious. You can find them on TH-cam.

  • @rayan361ify
    @rayan361ify 4 ปีที่แล้ว

    Yes !!! DS thanks Ben .👍

  • @salahalhashmi6528
    @salahalhashmi6528 3 ปีที่แล้ว

    thanks for this course

  • @iamjohnhenry
    @iamjohnhenry 4 ปีที่แล้ว +7

    You mention that a hash table (object) is implemented as an array, but it was originally the other way around -- the first implementation of javascript lacked "real" arrays and implemented them by adding a "length" method to an object that used number converted to strings as keys. Not sure about the underlying implementation though...
    Also, I don't think this is technically a hash function as the hashStringToInt function's run time is dependent upon string length and not constant.
    I want to add, however, that I recently discovered your channel and I really like the stuff you're doing here! Keep up the good work!

    • @31redorange08
      @31redorange08 3 ปีที่แล้ว

      Why does the hash function have to be constant? How to achieve this?

    • @marcossidoruk8033
      @marcossidoruk8033 ปีที่แล้ว

      @@31redorange08 it doesn't.

    • @marcossidoruk8033
      @marcossidoruk8033 ปีที่แล้ว

      Hash tables are not constant time with respect to key length only with respect to number of elements.

    • @31redorange08
      @31redorange08 ปีที่แล้ว

      @@marcossidoruk8033 I know. I just wanted to bust their "knowledge" in a nonconfrontational way. 🙂

  • @superchillh3o
    @superchillh3o 4 ปีที่แล้ว

    thanks for sharing!

  • @pullrequest1481
    @pullrequest1481 ปีที่แล้ว

    This is crazy!!! ❤❤❤❤

  • @nicolasguillenc
    @nicolasguillenc 3 ปีที่แล้ว +1

    Thanks man. 🙏🏽

  • @petarthecodehunter3333
    @petarthecodehunter3333 ปีที่แล้ว

    Thank you!

  • @denistsoi
    @denistsoi 4 ปีที่แล้ว

    You can use //? to show the output at the end of the line number instead of console.log

    • @bawad
      @bawad  4 ปีที่แล้ว

      I think that's only in the premium version

  • @FunctionGermany
    @FunctionGermany 3 ปีที่แล้ว +1

    But why would you want to do this when we have Map?

  • @Kenbomp
    @Kenbomp ปีที่แล้ว

    . Js can get quite complicated. But it work

  • @Tonestire
    @Tonestire 3 ปีที่แล้ว

    can you go through the other extensions you have installed in vs code? what's the one that shows you the green boxes on the left?

    • @kjl3080
      @kjl3080 3 ปีที่แล้ว

      That’s just a visual extension for uncommitted/unsaved changes

    • @Tonestire
      @Tonestire 3 ปีที่แล้ว

      @@kjl3080 what's it called?

    • @kjl3080
      @kjl3080 3 ปีที่แล้ว

      @@Tonestire idk what that specific theme is called, but you should be able to find it in the extensions marketplace iirc

  • @arturluisoliveira
    @arturluisoliveira 3 ปีที่แล้ว +1

    sometimes I got the impression that ben is always laughing on the inside. hahaha.

  • @CardinalHijack
    @CardinalHijack 4 ปีที่แล้ว

    Do you or does anyone know if places like Google will ask you to do this in an interview?

    • @bawad
      @bawad  4 ปีที่แล้ว

      Nope

  • @samial-jabar9861
    @samial-jabar9861 3 ปีที่แล้ว

    Very nice video

  • @albertwoo6246
    @albertwoo6246 4 ปีที่แล้ว

    I have a dumb question. In some other languages like c#, if the array`s length is 10, but your hash function calculated the index to be 13 then how can you set value to that index because the index can only be from 0 to 9? Looks like in javascript the array is a dictionary right?

    • @bawad
      @bawad  4 ปีที่แล้ว +1

      that's why we mod by the length of the array so we never get a number bigger

    • @albertwoo6246
      @albertwoo6246 4 ปีที่แล้ว

      @@bawad Thanks! I did not noticed that.

  • @svmathtutor
    @svmathtutor 3 ปีที่แล้ว

    1:27 , 2:55 Ctrl + Shift + P on Windows machine to get the menu to Start Quokka on Current File.

  • @md.akib5124
    @md.akib5124 4 ปีที่แล้ว +1

    My DS class got so easy

  • @nilokillian
    @nilokillian 4 ปีที่แล้ว

    there is a bug in hashStringToInt func's logic : in For loop you're re-assigning Hash variable every circle. Someone suggested in the comment section to use += which is right but we also need to move the modulus out of the loop, otherwise we go outside of the array's length so

  • @JeremiahPeoples
    @JeremiahPeoples 2 ปีที่แล้ว

    This is good.

  • @filippasek6
    @filippasek6 4 ปีที่แล้ว +1

    Your hash function only takes the last char

  • @sbin9161
    @sbin9161 2 ปีที่แล้ว

    Thanks :)

  • @tahaAFK
    @tahaAFK ปีที่แล้ว

    3:55 well you can use string as an index there in JavaScript.

  • @christalley5192
    @christalley5192 4 ปีที่แล้ว +1

    This was super helpful. Small question about the time complexity. Since the resizing only occurs at a certain point, will the time complexity still remain O(n) at the worst? Great video though thank you.

  • @redlobsta1
    @redlobsta1 2 ปีที่แล้ว

    @10:16 for lines 4 to 6, why would you want to use a for loop that runs i many times, to finally generate a single number (hash) at the end,
    seems a bit unnecessary as lets say our string is "firstName" - all that matters is charCodeAt('e') (the last letter) and that determines our hash, all the other letters "firstNam" when run through the for loop, get overwritten by the last iteration.

  • @dannyjiujitsu
    @dannyjiujitsu ปีที่แล้ว

    This video was all over the place.

  • @walo3000
    @walo3000 4 ปีที่แล้ว +2

    you can also do ```person['lastName'] //?``` and get the same result as the console.log

    • @ugurcoskun5195
      @ugurcoskun5195 4 ปีที่แล้ว

      premium?

    • @walo3000
      @walo3000 4 ปีที่แล้ว +1

      @@ugurcoskun5195 I didnt realize before, but yes, its available in pro version. I will recommend Pro version, it has useful features.

  • @sqwale7
    @sqwale7 2 ปีที่แล้ว

    Seems to be a bug?
    Your hush function will only be based on the last character of your string. Not a function of the entire string!
    What you may want to do is create a running sum of your salt + charCodeAt(i)

  • @ebosetalee7159
    @ebosetalee7159 3 ปีที่แล้ว

    Although this was uploaded in 2019, I noticed something while using new Array(this.size), If the size of our array is 100 and add an item to 200 your array automatically increases to 201. Therefore, no need to resize the array.

    • @alext5497
      @alext5497 2 ปีที่แล้ว

      If the new item has a collision, the size will not increase. Also, depending on which part of the video your referring to, he is not always just pushing items to the end, so again, your not increasing the size.
      The way I would prefer to do it is to make a internal method getsize () and call it only if needed to avoid unnecessary computation.

  • @antonomelchuk4795
    @antonomelchuk4795 3 ปีที่แล้ว

    How do you show console.log in real time?

    • @kjl3080
      @kjl3080 3 ปีที่แล้ว

      Quippa I think

    • @kjl3080
      @kjl3080 3 ปีที่แล้ว

      *quokka it’s not free

  • @luishenriqueandradepellizz680
    @luishenriqueandradepellizz680 2 ปีที่แล้ว

    I laugh so LOUD after he says to himself at 22:13 * Oh yeah I`m just a NOOB *, but I was crying inside because I have no idea what was happening and needed to pause while(myUnderstanding < 1)

  • @chungleee
    @chungleee 4 ปีที่แล้ว

    is there a difference between obj.foo and obj['foo'] ?

    • @FauzulChowdhury
      @FauzulChowdhury 4 ปีที่แล้ว +2

      No in terms of expected result. Yes if you are e.g, Trying to make a object key from the value of foo. obj.foo won't work but obj['foo'] will work.

    • @ericlarson7740
      @ericlarson7740 4 ปีที่แล้ว +1

      The 2nd option allows for more property names possibilities with characters that wouldn't be allowed with the 1st option. Take for instance:
      var obj = {'//bar': 'This property name is only possible with quotations'};
      obj.//bar is not valid while obj['//bar'] is allowed.

    • @FauzulChowdhury
      @FauzulChowdhury 4 ปีที่แล้ว

      @@ericlarson7740 ya... Thanks for a better clarification. :)

    • @vorname1485
      @vorname1485 4 ปีที่แล้ว

      Under the hood its the same operation. But syntactically the former does not allow you to use space or other tokens, because it would be indistinguishable, so you have the later syntax, which is distinguishable.

  • @hakanaki
    @hakanaki 2 ปีที่แล้ว

    Can someone pls explain the difference between a hash map and a hash table ?

    • @obetreyes9187
      @obetreyes9187 2 ปีที่แล้ว +1

      Here's the way I understand it:
      Hash Table: what we call the concept in Computer Science
      Hash Map: what it is called in Java
      Hash Set (HashSet): the case where we only care about the unique keys (or you can see it as a Hash Table where we ignore the values, we just want to know what is the set of unique keys)
      Or simply,
      Hash Table (CS) = HashMap (Java) = Dictionary (Python)
      Hash Set (CS) = HashSet (Java) = Set (Python)

    • @hakanaki
      @hakanaki 2 ปีที่แล้ว

      @@obetreyes9187 thank you very much

  • @aleksd286
    @aleksd286 4 ปีที่แล้ว

    Do you think someone will ever need to create their own hash table in JS like that? Because github/npm etc are full of somebody else's made hash tables

    • @candfsolutions
      @candfsolutions 4 ปีที่แล้ว +2

      In the beginning, re-using existing modules is fine, but eventually it's good to understand what's happening under the hood. Building your own is the often best way to get there.
      For example, after lightly using MVC frameworks I decided I needed to understand them better, so I built my own. It's nothing special and certainly nothing I'll put into production, but when I was done I had a full, solid grasp of the concepts and mechanics of MVC, as well as some of the tradeoffs/pitfalls involved in using the pattern.

    • @aleksd286
      @aleksd286 4 ปีที่แล้ว

      @@candfsolutions indeed for self learning I guess this is ideal, probably these type of stuff you don't want to use in production just, unless you want to be responsible for maintaining it, bug fixing, and adding features

    • @bawad
      @bawad  4 ปีที่แล้ว +1

      99.9999% of the time you won't need to implement your own hash table.
      I've always used the one already implemented for me

  • @vorname1485
    @vorname1485 4 ปีที่แล้ว +2

    Do you know this? The way you assign the (arrow)-methods is equivalent to assigning via *this.getItem = expression* , which means its bound to the HashTable instance and not prototype. Means, each HashTable method will create new method instances, instead of those methods being instantiated once on prototype. That is the difference between the syntax-sugared *getItem(key) {}* and *getItem = (key) => {}* (ignoring the this context on arrow function). The former is on prototype, the later on instance. Does not make much difference here though, but good to know if you have a lot of instantiations of those types.

    • @maheshsundaram8012
      @maheshsundaram8012 4 ปีที่แล้ว

      Thank you for explaining that

    • @mihaimanole2643
      @mihaimanole2643 4 ปีที่แล้ว

      That means that in the second form (arrow) I can access the instance properties directly, like table instead of this.table, isn’t it?

    • @vorname1485
      @vorname1485 4 ปีที่แล้ว +1

      @@mihaimanole2643 no, you can not because table is not a local variable. also when desugared. So you will still need this.

  • @rorisjack1218
    @rorisjack1218 4 ปีที่แล้ว

    Hey man, great video!
    Just a question, what font are you using on VSCode? On Windows my fonts look really pixelated and ugly. Thanks!

    • @bawad
      @bawad  4 ปีที่แล้ว

      I think I'm using the default one

    • @kjl3080
      @kjl3080 3 ปีที่แล้ว

      Try ClearType or increasing your font size

  • @RavnitSuri
    @RavnitSuri 3 ปีที่แล้ว

    I don't understand... why are we making these with Arrays again and not objects?

    • @vitorgouveia5378
      @vitorgouveia5378 3 ปีที่แล้ว

      Me too, like, why not just use objects as shown in the beginning of the vídeo? Why do all that extra work?

  • @peterm.souzajr.2112
    @peterm.souzajr.2112 4 ปีที่แล้ว

    thanks

  • @ExtremelyTastyBread
    @ExtremelyTastyBread 2 ปีที่แล้ว

    Google better not ask me to code one of these entirely from scratch in my phone screen tomorrow, because I guarantee I can't do it

  • @vorname1485
    @vorname1485 4 ปีที่แล้ว

    Noticed, there is probably a bug (did not test it, just from watching the video) with empty string passed as key, the length will be zero and so the returned int key will be 17, which is out of bounds of the initial table of length 3 :)

    • @bawad
      @bawad  4 ปีที่แล้ว

      nice find!

    • @vorname1485
      @vorname1485 4 ปีที่แล้ว

      @@bawad I like your interesst in understanding how things work. I also like to do stuff like that myself for fun and it helps understand things better and being more creative in finding solutions for problems. Especially, like in this case, when its actually part of language, but do it more *low level* (if that is the correct term here..) yourself. For example some ui & interaction rendered on canvas, including event handling - you can obviously not add event listeners to drawn objects natively on a canvas. Layouting system to arrange ui elements, etc.

  • @binrui
    @binrui 4 ปีที่แล้ว

    Delicious :)

  • @NurthinAziz
    @NurthinAziz 4 ปีที่แล้ว

    Subscribed

    • @bawad
      @bawad  4 ปีที่แล้ว

      welcome :)

  • @ekvedaras
    @ekvedaras 3 ปีที่แล้ว

    Not that anybody asked, but I always watch your videos at 2x speed. Cool stuff though :) I would have liked a few sentences about why and when to use something like this or is it just a fun little exercise.

  • @0xatul
    @0xatul ปีที่แล้ว

    I miss the old Ben

  • @MrEnsiferum77
    @MrEnsiferum77 4 ปีที่แล้ว +2

    The problem with this data structure courses is that no one like to take deep dive in more hard structures like trees(but no binary or n-ary trees) etc.. and more complicated alghortims that are used in AI and are tightly connected with trees and similar structures.

    • @Rei-m3g
      @Rei-m3g 2 ปีที่แล้ว

      haha . yea

    • @MrEnsiferum77
      @MrEnsiferum77 2 ปีที่แล้ว

      @@Rei-m3g Metallicaaaaaa

  • @julianavar3836
    @julianavar3836 4 ปีที่แล้ว

    or you could use a map

  • @amanlearnscode
    @amanlearnscode 4 ปีที่แล้ว +1

    the load factor of HashMap in Java is 0.75 :)

    • @rickross9829
      @rickross9829 4 ปีที่แล้ว

      Java or JS?

    • @mihaimanole2643
      @mihaimanole2643 4 ปีที่แล้ว

      rick ross It’s very handy to peek the implementation of HashMap from Java then the one from V8 or other JavaScript engine. Which, of course, will be not implemented in JavaScript, but most likely in C++.

  • @hamzadata
    @hamzadata 2 ปีที่แล้ว

    We now know why you had to wear glasses

  • @bloodandbonezzz
    @bloodandbonezzz 4 ปีที่แล้ว +4

    Why use a hash when you can use an object?

    • @jeromesnail
      @jeromesnail 4 ปีที่แล้ว +1

      I guess it's just to show how it works under the hood.

    • @sahilGupta217
      @sahilGupta217 4 ปีที่แล้ว

      @@jeromesnail but actually which one is used more often??

  • @colloidalsilver177
    @colloidalsilver177 2 ปีที่แล้ว

    What do you mean by “spreading out the keys” ?you’ll have to excuse me im a dummy

  • @azumatomlinson3474
    @azumatomlinson3474 2 ปีที่แล้ว

    My bookmarks:
    5:48

  • @MrBazookatoon
    @MrBazookatoon 4 ปีที่แล้ว

    Why would you need a hashtable in Javascript when you have JSON?

    • @bawad
      @bawad  4 ปีที่แล้ว +2

      I wouldn't actually use this, it's more for learning purposes

  • @diegoalexander1425
    @diegoalexander1425 2 ปีที่แล้ว

    Crack