0 1 00:00:00,300 --> 00:00:00,580 All right. 1 2 00:00:00,590 --> 00:00:04,040 So here comes the answer to the challenge. 2 3 00:00:04,090 --> 00:00:09,580 First things first because Lodash is available to us through NPM, then we're going to install it in 3 4 00:00:09,580 --> 00:00:15,310 the same way that we've installed Express EJS or Request to any of the previous libraries that we've 4 5 00:00:15,310 --> 00:00:16,430 worked with. 5 6 00:00:16,870 --> 00:00:25,120 Firstly we have to Control + C to quit our server and then we're going to run npm i or npm install and then 6 7 00:00:25,120 --> 00:00:30,260 we're going to spell out lodash and then we'll let that install in the background. 7 8 00:00:30,270 --> 00:00:36,090 Now the next thing we need to read in the documentation is how to use it using Node.js. And the way 8 9 00:00:36,090 --> 00:00:44,070 that they prefer you to use the library is to create a new variable using a underscore or what is also 9 10 00:00:44,070 --> 00:00:46,520 known as a low dash. 10 11 00:00:46,560 --> 00:00:49,380 That is how some people might refer to that symbol. 11 12 00:00:49,560 --> 00:00:55,480 Now in modern versions of Javascript we favor constant over var, so we're going to change that. 12 13 00:00:55,680 --> 00:01:00,490 And then we're going to require lodash so that we tap into all of its capabilities. 13 14 00:01:00,510 --> 00:01:03,570 Let's go into Atom and do that right at the top. 14 15 00:01:03,690 --> 00:01:09,480 So we're going to create a new const and it's going to be a underscore or a lodash. And then we'll 15 16 00:01:09,480 --> 00:01:15,430 get to set that to equal require the package that is lodash. 16 17 00:01:15,660 --> 00:01:20,020 And now we have access to all of the utilities in this library. 17 18 00:01:20,100 --> 00:01:26,070 Now as I mentioned, the particular one that we're interested in is the one that turns everything into 18 19 00:01:26,070 --> 00:01:34,380 a lower case and ignores all of the dashes or the underscores so that we get a clear text that we can 19 20 00:01:34,380 --> 00:01:41,250 work with and we can compare. In order to use this method they've shown you appear that you simply write 20 21 00:01:41,330 --> 00:01:47,760 underscore, which refers to the lodash utility library, .and then we specify the name of the method 21 22 00:01:48,060 --> 00:01:54,270 which is lowercase and then inside some parentheses we specify a string. 22 23 00:01:54,270 --> 00:01:57,810 Let's go ahead and do that over here. 23 24 00:01:57,810 --> 00:02:03,600 Now we want to convert our requested title from whatever format it is that the user put in here. 24 25 00:02:03,630 --> 00:02:10,670 They could have an uppercase, lowercase, kebab case, snake case, whatever it is they decided to use. 25 26 00:02:10,720 --> 00:02:15,560 We're going to convert it to the same format by using that lowercase method. 26 27 00:02:15,570 --> 00:02:24,810 So now we're going to say const requestedTitle is equal to underscore or lodash .lowercase and then 27 28 00:02:24,810 --> 00:02:31,310 we're going to open a set of parentheses and inside here is where we're going to put our string. 28 29 00:02:31,980 --> 00:02:36,830 Now if you only want to convert a single string then you can simply specify it like this. 29 30 00:02:36,870 --> 00:02:42,670 But if you have an array of strings then you can also put it into an array like so. 30 31 00:02:43,640 --> 00:02:45,490 Both methods will work. 31 32 00:02:45,800 --> 00:02:53,190 So now we have our requestedTitle converted to lowercase, but our storedTitle is still capitalized right? 32 33 00:02:53,480 --> 00:02:57,700 And so we have to apply the same method to the storedTitle. 33 34 00:02:57,770 --> 00:03:05,600 So let's do the same down here. _.lowercase open a set of parentheses and include the 34 35 00:03:05,600 --> 00:03:08,580 thing that we want to convert which is our post.title. 35 36 00:03:08,900 --> 00:03:16,520 So now if we hit save and we head back into our console and we restart our Node server and then we go 36 37 00:03:16,520 --> 00:03:24,290 ahead and create a brand new post, just go over to compose let's just call it Another post and then I'm going 37 38 00:03:24,290 --> 00:03:27,750 to paste in some lorem ipsum, hit publish 38 39 00:03:27,780 --> 00:03:29,490 and now I have access to that. 39 40 00:03:29,720 --> 00:03:36,440 And then over here in the URL I'm going to tap into the route that is /posts/ 40 41 00:03:36,620 --> 00:03:45,410 another-post and the URL is all in lowercase whereas our title is-- has a capitalized another and then 41 42 00:03:45,410 --> 00:03:47,390 it's got a space and then it's got post. 42 43 00:03:47,420 --> 00:03:49,600 But I'm going to use kebab case over here 43 44 00:03:49,610 --> 00:03:52,880 so I have a hyphen between another and post. 44 45 00:03:53,060 --> 00:04:00,830 And now when I hit enter and I check my console, I still get a match found because we've converted this 45 46 00:04:00,830 --> 00:04:07,370 title and this part of the parameter both into lowercase, we've thrown away all the hyphens or underscores 46 47 00:04:07,430 --> 00:04:13,010 and we just have a clear text that both now match. As long as those strings match and they're in the 47 48 00:04:13,010 --> 00:04:15,750 right order then we will get a match. 48 49 00:04:15,800 --> 00:04:18,910 And this is going to set us up for the next challenge.