How to Implement a Hash Table in JavaScript

  Рет қаралды 105,348

Ben Awad

Ben Awad

Күн бұрын

Пікірлер: 180
@Akshatgiri
@Akshatgiri 5 жыл бұрын
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 4 жыл бұрын
It had to be Google、Facebook、Amazon interview i guess XD
@MrPaulsonantajo
@MrPaulsonantajo 3 жыл бұрын
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.
@viv_tried_coding
@viv_tried_coding 2 жыл бұрын
Really bro
@kzakaria91
@kzakaria91 5 жыл бұрын
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 жыл бұрын
I like your videos Ben, unique content and always questioning how things are made.
@lsamax4468
@lsamax4468 5 жыл бұрын
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 5 жыл бұрын
Jep. Been couple of weeks now, and not too many people who noticed this, it seems.
@bawad
@bawad 5 жыл бұрын
Good catch idk how I forgot about this
@stephenyin3509
@stephenyin3509 5 жыл бұрын
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!
@sbrugby1
@sbrugby1 5 жыл бұрын
great tip on Quokka. It feels like a jupyter notebook or something for js in vscode. I'm loving it.
@nstwin9
@nstwin9 5 жыл бұрын
Yessss! More data structures and algorithm videos please 🙏🙏🙏🙏🙏🙏🙏🙏🙏
@Jason_Lucero
@Jason_Lucero 3 жыл бұрын
Damn ben, never really watched you for your tutorials but damn, this was clean
@purdysanchez
@purdysanchez 5 жыл бұрын
Great job on a sample implementation of a hashtable in JS!
@IlhanNegis
@IlhanNegis 5 жыл бұрын
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 5 жыл бұрын
oh really, that's interesting, so how does the object work underneath?
@IlhanNegis
@IlhanNegis 5 жыл бұрын
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 5 жыл бұрын
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 5 жыл бұрын
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 5 жыл бұрын
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)
@tajpouria
@tajpouria 5 жыл бұрын
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 KZbin about it, best regards...
@YaohanChen
@YaohanChen 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 5 жыл бұрын
need to be careful about recursion in that case
@28bits20
@28bits20 5 жыл бұрын
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 5 жыл бұрын
good catch
@31redorange08
@31redorange08 4 жыл бұрын
Bad catch. There will either be an array or undefined, never 0 or an empty string.
@28bits20
@28bits20 4 жыл бұрын
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 3 жыл бұрын
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 3 жыл бұрын
ok never mind I get it now, took a moment :D
@lukehatcher98
@lukehatcher98 4 жыл бұрын
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
@mohamedaljamil6334
@mohamedaljamil6334 4 жыл бұрын
I finally understood hash tables. thank you
@TadesseDev
@TadesseDev 2 жыл бұрын
I am dancing now 😎, because I know the error that happens as you type it. 21:00, Great content buddy. Subscribed.
@MachiriReviews
@MachiriReviews 2 жыл бұрын
This is a really good guide. From this I was also able to write a function that reassigns values.
@MrREALball
@MrREALball 5 жыл бұрын
2001 isnt prime, cuz 2+0+0+1 % 3 = 0, so u could divide it by 3
@ditoorkodashvili6018
@ditoorkodashvili6018 4 жыл бұрын
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.
@jmoo4457
@jmoo4457 5 жыл бұрын
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 5 жыл бұрын
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 5 жыл бұрын
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 KZbin.
@paco3447
@paco3447 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.
@iamjohnhenry
@iamjohnhenry 4 жыл бұрын
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 4 жыл бұрын
Why does the hash function have to be constant? How to achieve this?
@marcossidoruk8033
@marcossidoruk8033 2 жыл бұрын
@@31redorange08 it doesn't.
@marcossidoruk8033
@marcossidoruk8033 2 жыл бұрын
Hash tables are not constant time with respect to key length only with respect to number of elements.
@31redorange08
@31redorange08 2 жыл бұрын
@@marcossidoruk8033 I know. I just wanted to bust their "knowledge" in a nonconfrontational way. 🙂
@fezekileplaatyi7224
@fezekileplaatyi7224 3 жыл бұрын
Hey Ben, do you have other tutorials for other Data Structures? Man you explained this very nicely and easily
@JaspreetSingh-eq2yk
@JaspreetSingh-eq2yk 4 жыл бұрын
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 4 жыл бұрын
Yes, his bad, because rn it only hashes the last character
@juanmarino1186
@juanmarino1186 2 жыл бұрын
watching you code is fun
@producdevity
@producdevity 5 жыл бұрын
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 5 жыл бұрын
It's useful as a teaching example of a basic hashtable implementation
@spaghettiking653
@spaghettiking653 4 жыл бұрын
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.
@OfferoC
@OfferoC 5 жыл бұрын
Great video, thanks. I would love a video comparing different hash functions.
@Sinan997
@Sinan997 Жыл бұрын
dude this is golden, appreciated that
@svmathtutor
@svmathtutor 3 жыл бұрын
1:27 , 2:55 Ctrl + Shift + P on Windows machine to get the menu to Start Quokka on Current File.
@theemacsen1518
@theemacsen1518 5 жыл бұрын
Great video as always Ben!!
@ltserge3226
@ltserge3226 2 жыл бұрын
at 20:40 what command did you do to copy the line like that?
@tahaAFK
@tahaAFK Жыл бұрын
3:55 well you can use string as an index there in JavaScript.
@jasonjones5079
@jasonjones5079 5 жыл бұрын
Really enjoyed this!
@denistsoi
@denistsoi 5 жыл бұрын
You can use //? to show the output at the end of the line number instead of console.log
@bawad
@bawad 5 жыл бұрын
I think that's only in the premium version
@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)
@arturluisoliveira
@arturluisoliveira 4 жыл бұрын
sometimes I got the impression that ben is always laughing on the inside. hahaha.
@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.
@vorname1485
@vorname1485 5 жыл бұрын
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 5 жыл бұрын
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 жыл бұрын
@@mihaimanole2643 no, you can not because table is not a local variable. also when desugared. So you will still need this.
@joestrkr
@joestrkr 4 жыл бұрын
Very cool stuff. Love your channel :)
@bawad
@bawad 4 жыл бұрын
Thanks!
@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
@31redorange08
@31redorange08 4 жыл бұрын
And what's the bug?
@anantsharma13
@anantsharma13 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?
@walo3000
@walo3000 5 жыл бұрын
you can also do ```person['lastName'] //?``` and get the same result as the console.log
@ugurcoskun5195
@ugurcoskun5195 5 жыл бұрын
premium?
@walo3000
@walo3000 5 жыл бұрын
@@ugurcoskun5195 I didnt realize before, but yes, its available in pro version. I will recommend Pro version, it has useful features.
@hugothms
@hugothms 3 жыл бұрын
That's very clear ! Thanks buddy
@claydaman22
@claydaman22 5 жыл бұрын
This is cool and all but how would you use this in a real word app? Would I persist this to a DB?
@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 3 жыл бұрын
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.
@riexrickgaming
@riexrickgaming 4 жыл бұрын
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
@dannyjiujitsu
@dannyjiujitsu Жыл бұрын
This video was all over the place.
@khadijasheikh8144
@khadijasheikh8144 2 жыл бұрын
Thank you so much this video is benefitfull i appreciate it .
@godnessy
@godnessy 2 жыл бұрын
Very cool video, 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
@lucasdelbel7376
@lucasdelbel7376 3 жыл бұрын
Awesome video.Thank you so much.
@Jun-zq3bn
@Jun-zq3bn 3 жыл бұрын
what extension or shortcut did you use to auto input ;
@FunctionGermany
@FunctionGermany 4 жыл бұрын
But why would you want to do this when we have Map?
@inasuma8180
@inasuma8180 4 жыл бұрын
Is there a more optimized way to resize the hash table? 🤔
@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)
@Tonestire
@Tonestire 4 жыл бұрын
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 4 жыл бұрын
That’s just a visual extension for uncommitted/unsaved changes
@Tonestire
@Tonestire 4 жыл бұрын
@@kjl3080 what's it called?
@kjl3080
@kjl3080 4 жыл бұрын
@@Tonestire idk what that specific theme is called, but you should be able to find it in the extensions marketplace iirc
@adhupraba
@adhupraba 3 жыл бұрын
great video... also what is your vs code's font name? I'd like to set for mine too...
@Kenbomp
@Kenbomp 2 жыл бұрын
. Js can get quite complicated. But it work
@albertwoo6246
@albertwoo6246 5 жыл бұрын
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 5 жыл бұрын
that's why we mod by the length of the array so we never get a number bigger
@albertwoo6246
@albertwoo6246 5 жыл бұрын
@@bawad Thanks! I did not noticed that.
@vorname1485
@vorname1485 5 жыл бұрын
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 5 жыл бұрын
nice find!
@vorname1485
@vorname1485 5 жыл бұрын
@@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.
@filippasek6
@filippasek6 4 жыл бұрын
Your hash function only takes the last char
@md.akib5124
@md.akib5124 5 жыл бұрын
My DS class got so easy
@hanifabeg1699
@hanifabeg1699 3 жыл бұрын
which extension is he using for this auto onscreen console
@ajaykrishnareddy
@ajaykrishnareddy 5 жыл бұрын
Hi , I currently using react hooks is there any way that use call back after setting the state using useState hook
@bawad
@bawad 5 жыл бұрын
what do you mean?
@evanstapp
@evanstapp 5 жыл бұрын
Good one Ben
@christalley5192
@christalley5192 4 жыл бұрын
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.
@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
@SinanAkkoyun
@SinanAkkoyun 3 жыл бұрын
How high is ur monitor?
@JeremiahPeoples
@JeremiahPeoples 3 жыл бұрын
This is good.
@amanlearnscode
@amanlearnscode 5 жыл бұрын
the load factor of HashMap in Java is 0.75 :)
@rickross9829
@rickross9829 5 жыл бұрын
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++.
@salahalhashmi6528
@salahalhashmi6528 3 жыл бұрын
thanks for this course
@MrEnsiferum77
@MrEnsiferum77 5 жыл бұрын
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.
@MrEnsiferum77
@MrEnsiferum77 2 жыл бұрын
@Lewra Metallicaaaaaa
@nicolasguillenc
@nicolasguillenc 3 жыл бұрын
Thanks man. 🙏🏽
@aleksd286
@aleksd286 5 жыл бұрын
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 5 жыл бұрын
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 5 жыл бұрын
@@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 5 жыл бұрын
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
@brNoMundo123
@brNoMundo123 2 жыл бұрын
Great video!
@frankie_goestohollywood
@frankie_goestohollywood 4 жыл бұрын
Thank you, Ben!!! :-)
@benejix
@benejix 5 ай бұрын
how does one even get this good?
@antonomelchuk4795
@antonomelchuk4795 4 жыл бұрын
How do you show console.log in real time?
@kjl3080
@kjl3080 4 жыл бұрын
Quippa I think
@kjl3080
@kjl3080 4 жыл бұрын
*quokka it’s not free
@RavnitSuri
@RavnitSuri 4 жыл бұрын
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?
@rayan361ify
@rayan361ify 5 жыл бұрын
Yes !!! DS thanks Ben .👍
@hamzadata
@hamzadata 3 жыл бұрын
We now know why you had to wear glasses
@chungleee
@chungleee 5 жыл бұрын
is there a difference between obj.foo and obj['foo'] ?
@FauzulChowdhury
@FauzulChowdhury 5 жыл бұрын
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 5 жыл бұрын
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 5 жыл бұрын
@@ericlarson7740 ya... Thanks for a better clarification. :)
@vorname1485
@vorname1485 5 жыл бұрын
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 3 жыл бұрын
Can someone pls explain the difference between a hash map and a hash table ?
@obetreyes9187
@obetreyes9187 3 жыл бұрын
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 3 жыл бұрын
@@obetreyes9187 thank you very much
@bloodandbonezzz
@bloodandbonezzz 5 жыл бұрын
Why use a hash when you can use an object?
@jeromesnail
@jeromesnail 5 жыл бұрын
I guess it's just to show how it works under the hood.
@sahilGupta217
@sahilGupta217 5 жыл бұрын
@@jeromesnail but actually which one is used more often??
@azumatomlinson3474
@azumatomlinson3474 2 жыл бұрын
My bookmarks: 5:48
@ekvedaras
@ekvedaras 4 жыл бұрын
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.
@vitalino1981
@vitalino1981 5 ай бұрын
This implementation lacks the possibility to overwrite existing value using same key.
@pullrequest1481
@pullrequest1481 2 жыл бұрын
This is crazy!!! ❤❤❤❤
@rorisjack1218
@rorisjack1218 5 жыл бұрын
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 5 жыл бұрын
I think I'm using the default one
@kjl3080
@kjl3080 4 жыл бұрын
Try ClearType or increasing your font size
@samial-jabar9861
@samial-jabar9861 4 жыл бұрын
Very nice video
@superchillh3o
@superchillh3o 5 жыл бұрын
thanks for sharing!
@MrBazookatoon
@MrBazookatoon 5 жыл бұрын
Why would you need a hashtable in Javascript when you have JSON?
@bawad
@bawad 5 жыл бұрын
I wouldn't actually use this, it's more for learning purposes
@petarthecodehunter3333
@petarthecodehunter3333 2 жыл бұрын
Thank you!
@colloidalsilver177
@colloidalsilver177 3 жыл бұрын
What do you mean by “spreading out the keys” ?you’ll have to excuse me im a dummy
@julianavar3836
@julianavar3836 4 жыл бұрын
or you could use a map
@elbozo5723
@elbozo5723 2 жыл бұрын
or… and mark my words… let table; table[“key”] = value;
@okonkwo.ify18
@okonkwo.ify18 2 жыл бұрын
U are wrong. Arrays are objects in JavaScript not the other way around
@sbin9161
@sbin9161 3 жыл бұрын
Thanks :)
@hamyncheese
@hamyncheese 5 жыл бұрын
firstname, lastname, and age will always resolve to the same integer in your hash function because you made the mistake of assigning the integer code of the final "e" of each string to to the hash variable by using "hash = int_code" instead of adding the codes of each letter in the string as you iterated through the chars using "hash += int_code". Also, hashing non-unique keys will ALWAYS cause the massive collisions you had. In this example, you probably should have used the actual last name (ie "Smith") to create the hash and return firstName, age , and DOB, instead of using the key "lastName". Because of these errors, your resize function in this example is irrelevant.
@bawad
@bawad 5 жыл бұрын
good catch += is what I meant to do 🤦
@31redorange08
@31redorange08 4 жыл бұрын
Incorrect. The current value of the hash is used in the next iteration.
@hamyncheese
@hamyncheese 4 жыл бұрын
@@31redorange08 My apologies if I am incorrect. I'm pretty sure I tested it at the time of my comment. I was watching this video because I am not an experienced programmer.
@0xatul
@0xatul 2 жыл бұрын
I miss the old Ben
Beginner React.js Coding Interview (ft. Clément Mihailescu)
36:31
Ben Awad
Рет қаралды 2,2 МЛН
Hash Tables and Hash Functions
13:56
Computer Science Lessons
Рет қаралды 1,6 МЛН
1% vs 100% #beatbox #tiktok
01:10
BeatboxJCOP
Рет қаралды 67 МЛН
She made herself an ear of corn from his marmalade candies🌽🌽🌽
00:38
Valja & Maxim Family
Рет қаралды 18 МЛН
Мен атып көрмегенмін ! | Qalam | 5 серия
25:41
Quando A Diferença De Altura É Muito Grande 😲😂
00:12
Mari Maria
Рет қаралды 45 МЛН
How to Roll Your Own Auth
13:05
Ben Awad
Рет қаралды 125 М.
JavaScript Pro Tips - Code This, NOT That
12:37
Fireship
Рет қаралды 2,5 МЛН
Hash Tables - Beau teaches JavaScript
9:50
freeCodeCamp.org
Рет қаралды 96 М.
What Programming Font Should You Use?
4:12
Ben Awad
Рет қаралды 49 М.
JavaScript Data Structures: Getting Started
1:36:47
Academind
Рет қаралды 243 М.
Data Structures: Hash Tables
6:25
HackerRank
Рет қаралды 1,5 МЛН
The Async Await Episode I Promised
12:04
Fireship
Рет қаралды 1,1 МЛН
5 JavaScript Concepts You HAVE TO KNOW
9:38
James Q Quick
Рет қаралды 1,4 МЛН
React Typescript Tutorial
23:33
Ben Awad
Рет қаралды 576 М.
1% vs 100% #beatbox #tiktok
01:10
BeatboxJCOP
Рет қаралды 67 МЛН