Transcript from the "Bloom Filters Exercise" Lesson
>> Brian Holt: So, we are gonna go in here. We're going to click on the exercise down here. It's going to take you to one of my favorite websites, which is codepen.io. If you do not have a Code Pen account, you don't have to have one, but I would suggest having one.
[00:00:17] One just cuz I like the product, but two, what you can do up here is you can click Fork, and you can Fork my examples to your Code Pen, and then you can keep them afterwards. I think it's useful to refer back to code that you yourself have written.
>> Brian Holt: You saw on the previous screen that I have the answer on there as well, right. This is not a test, so you can definitely look at the answer if you are getting stuck or something like that. I would definitely suggest trying to solve it, right? That's the point of this and I think that there's great value in pushing yourself and particularly in those moments you are struggling to get to the answer and struggling to reason through things.
[00:01:01] I think that's when you learn the mos,t at least for me personally that's when I learned the most, so keep that in mind. The other thing I want to tell everyone listening is, this stuff is hard [LAUGH]. So if you're sitting here struggling and feeling someone else is getting it and you're not, it's okay.
[00:01:20] This is definitely difficult and I'm teaching you way too much material to learn in one sitting so if you're brain feels a little squishy afterwards you are not alone. My brain feels squishy just talking about it so we're all in this together, so that's just yeah, don't be too hard on yourself.
[00:01:58] And then we are running unit test down here at the bottom. So this is Jasmine, just very run-of-the-mill kind of old Jasmine, if we're being honest. It's going to run a couple unit tests here, and you know, once they passed it was turned up green right? Something I was suggest you do just throughout the entire day here if you click on Settings up here, go to Behavior, and turn off Auto-Updating Preview.
[00:02:31] It won't matter too much in this one. But when once we start getting into recursive things, it's gonna matter a whole lot. Otherwise you're gonna crash your browser. So definitely turn off Auto Updating Preview. Once you've done that, it won't just start running the code every time you type.
[00:02:48] What it's gonna do is it's going to give you this run button up here. So it's actually not going to run your code until you click run. That's a good trick to know. Another thing that I will suggest that you do or just another trick. You can hit, down on these unit tests, if you hit x, right, here.
[00:03:11] If I click Run after that. It's actually not going to run any of the tests that have x next to it, right? So you can see here there's three unit tests, but it has one pending, right? That just means that I'm skipping it right now, so you can kinda just focus on one test at a time.
[00:03:29] I find that to be useful as well.
>> Brian Holt: Lastly, CodePen has some quirks sometimes, so if I put, let's say I just say const function equals thing. Right, this is not going to compile because this function's a reserved word. It's going to give me a red exclamation point down there, which I find a little too subtle.
[00:03:53] I wish they were a little bit louder about it, but just, if your code's not doing anything and you're like why the hell is nothing happening, look for the red exclamation point. If you click on it, it's going to say, I don't know what this line is. And sometimes that error is far less or far more cryptic than that, just know that you probably have a syntax error somewhere.
>> Brian Holt: Okay, so those are things I definitely wanted to get in front of you. I found them very frustrating, so I'm trying to Lessen your frustration with this. So let's talk about what I want you to do. I want you to build a bloom filter. You can see, up here, that I gave you three functions, h1, h2, and h3.
[00:04:32] You'll put in some sort of string to this function. So you'll call it something like
>> Brian Holt: H1("Brian") right? And it's gonna give you back some number so if I say console.log Brian. Open my console here. See if I can make that a little bit bigger.
>> Brian Holt: Say run.
>> Brian Holt: You can see here I got 92 back from that function, right, cool? So that's how you're gonna do that same thing. And if I call that again with h2 it's gonna give me a different number. 80 and with h3 I get it with a yet different number.
[00:05:20] Cool, do we kind of see the pattern here? 0, that's interesting, neat.
>> Brian Holt: You don't have to care particularly how these work, right, it's using a library called XXH, that's what I was referring to earlier. And just using different seed values, but suffice to say, you don't actually have to care about that, just know that it's gonna give you a number between 0 and 100.
[00:05:45] Please make your bloom filter use 100 spaces. That's why I did that for you.
>> Brian Holt: And then you need to code up two methods here. One called add, one called check, right? So you will be able to add things to the Bloom filter and be able to check if something might be in the Bloom filter.
>> Brian Holt: Make sense?
>> Brian Holt: Cool, let's give you and just to let you know, this took me I think about 15 lines of code ish. So I'm gonna give you 15 minutes to do this, come back in 15 minutes and we'll talk about how to do this.