WEBVTT 0 00:00.300 --> 00:00.580 All right. 1 00:00.590 --> 00:04.040 So here comes the answer to the challenge. 2 00:04.090 --> 00:09.580 First things first because Lodash is available to us through NPM, then we're going to install it in 3 00:09.580 --> 00:15.310 the same way that we've installed Express EJS or Request to any of the previous libraries that we've 4 00:15.310 --> 00:16.430 worked with. 5 00:16.870 --> 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 00:25.120 --> 00:30.260 we're going to spell out lodash and then we'll let that install in the background. 7 00:30.270 --> 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 00:36.090 --> 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 00:44.070 --> 00:46.520 known as a low dash. 10 00:46.560 --> 00:49.380 That is how some people might refer to that symbol. 11 00:49.560 --> 00:55.480 Now in modern versions of Javascript we favor constant over var, so we're going to change that. 12 00:55.680 --> 01:00.490 And then we're going to require lodash so that we tap into all of its capabilities. 13 01:00.510 --> 01:03.570 Let's go into Atom and do that right at the top. 14 01:03.690 --> 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 01:09.480 --> 01:15.430 get to set that to equal require the package that is lodash. 16 01:15.660 --> 01:20.020 And now we have access to all of the utilities in this library. 17 01:20.100 --> 01:26.070 Now as I mentioned, the particular one that we're interested in is the one that turns everything into 18 01:26.070 --> 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 01:34.380 --> 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 01:41.330 --> 01:47.760 underscore, which refers to the lodash utility library, .and then we specify the name of the method 21 01:48.060 --> 01:54.270 which is lowercase and then inside some parentheses we specify a string. 22 01:54.270 --> 01:57.810 Let's go ahead and do that over here. 23 01:57.810 --> 02:03.600 Now we want to convert our requested title from whatever format it is that the user put in here. 24 02:03.630 --> 02:10.670 They could have an uppercase, lowercase, kebab case, snake case, whatever it is they decided to use. 25 02:10.720 --> 02:15.560 We're going to convert it to the same format by using that lowercase method. 26 02:15.570 --> 02:24.810 So now we're going to say const requestedTitle is equal to underscore or lodash .lowercase and then 27 02:24.810 --> 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 02:31.980 --> 02:36.830 Now if you only want to convert a single string then you can simply specify it like this. 29 02:36.870 --> 02:42.670 But if you have an array of strings then you can also put it into an array like so. 30 02:43.640 --> 02:45.490 Both methods will work. 31 02:45.800 --> 02:53.190 So now we have our requestedTitle converted to lowercase, but our storedTitle is still capitalized right? 32 02:53.480 --> 02:57.700 And so we have to apply the same method to the storedTitle. 33 02:57.770 --> 03:05.600 So let's do the same down here. _.lowercase open a set of parentheses and include the 34 03:05.600 --> 03:08.580 thing that we want to convert which is our post.title. 35 03:08.900 --> 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 03:16.520 --> 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 03:24.290 --> 03:27.750 to paste in some lorem ipsum, hit publish 38 03:27.780 --> 03:29.490 and now I have access to that. 39 03:29.720 --> 03:36.440 And then over here in the URL I'm going to tap into the route that is /posts/ 40 03:36.620 --> 03:45.410 another-post and the URL is all in lowercase whereas our title is-- has a capitalized another and then 41 03:45.410 --> 03:47.390 it's got a space and then it's got post. 42 03:47.420 --> 03:49.600 But I'm going to use kebab case over here 43 03:49.610 --> 03:52.880 so I have a hyphen between another and post. 44 03:53.060 --> 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 04:00.830 --> 04:07.370 title and this part of the parameter both into lowercase, we've thrown away all the hyphens or underscores 46 04:07.430 --> 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 04:13.010 --> 04:15.750 right order then we will get a match. 48 04:15.800 --> 04:18.910 And this is going to set us up for the next challenge.