1 00:00:00,640 --> 00:00:01,850 Welcome back, ladies and gentlemen. 2 00:00:01,870 --> 00:00:04,290 Today, we're going to talk about S10 features. 3 00:00:04,570 --> 00:00:08,940 So this is ECMAScript 2019 and we have done a lot. 4 00:00:09,130 --> 00:00:15,400 So today we're going to do flat and flat map methods, dream, start and trim and from entry's try and 5 00:00:15,400 --> 00:00:15,970 catch block. 6 00:00:16,220 --> 00:00:22,770 Now, let's start I'm going to give you this link to flat map so you can read more about it now. 7 00:00:22,780 --> 00:00:27,100 Create lectured and linked in your link, this lecture in your index file. 8 00:00:27,340 --> 00:00:29,840 And start with the first one with the flat. 9 00:00:30,400 --> 00:00:32,420 OK, so what is a flat method? 10 00:00:32,650 --> 00:00:41,290 So this method creates a new array with all separate elements concatenated into it, recursively up 11 00:00:41,770 --> 00:00:43,540 to the specified depth. 12 00:00:43,810 --> 00:00:49,450 OK, so for the first example, I'm going to create an array. 13 00:00:50,490 --> 00:00:56,490 And I'm going to just show you what is happening, so I'm going to say a one, and this array will be 14 00:00:57,030 --> 00:01:00,390 one, two, three, four, five and six. 15 00:01:00,690 --> 00:01:04,780 OK, if I consolatory, you will just be able to see the entire. 16 00:01:05,670 --> 00:01:10,110 So the flat method will not work on this array or it will work. 17 00:01:10,650 --> 00:01:13,410 So even if I do a. 18 00:01:14,580 --> 00:01:22,500 Not flat, you will see the same array back now if I create another array, let's say three, two, 19 00:01:22,770 --> 00:01:27,950 and if I have nested array inside here, oops, not like that. 20 00:01:28,050 --> 00:01:30,500 Let's say five and six. 21 00:01:30,880 --> 00:01:35,330 Now I can use the flat method and look what is happening. 22 00:01:35,340 --> 00:01:38,070 So first I'm just going to print out the. 23 00:01:39,670 --> 00:01:43,280 The Ureta right, so we have this inside. 24 00:01:43,870 --> 00:01:51,390 Good, we can see it, and if I use the flat method on top of it, it will flatten the array. 25 00:01:51,580 --> 00:01:55,360 So it will give me the ostry back to as it was. 26 00:01:55,610 --> 00:01:57,260 Let's make this one a little bit different. 27 00:01:58,870 --> 00:01:59,290 Nice. 28 00:01:59,710 --> 00:02:10,670 But what will happen if I have another level here and Yurie in inside a ternary 10 and 11? 29 00:02:11,050 --> 00:02:17,320 Now if I see if I just save it, then you will be able to see that eight. 30 00:02:18,310 --> 00:02:20,510 It's all all done, right? 31 00:02:20,530 --> 00:02:26,260 One, two, three, four, five, six, eight, but 10 and 11, there's a separate array in. 32 00:02:26,320 --> 00:02:27,190 Why is this happening? 33 00:02:27,730 --> 00:02:35,230 Well, the flat method, if we just did we just put it like this without any parameter, then it will 34 00:02:35,230 --> 00:02:39,730 go and flatten there, even if there is a one nested. 35 00:02:39,940 --> 00:02:45,170 But there is when there is a multiple deep level nesting, then it will work only on two levels. 36 00:02:45,340 --> 00:02:46,500 So this is a third level. 37 00:02:46,810 --> 00:02:48,790 So what we can do, we can just create here. 38 00:02:48,940 --> 00:02:51,970 We can just put here too, and that will sort it out. 39 00:02:51,970 --> 00:02:56,880 But sometimes in order to be sure that you can put ten and yeah, it will do the same trick. 40 00:02:57,370 --> 00:02:59,340 So that is the flat method. 41 00:02:59,560 --> 00:03:04,720 So the flat method again creates a new array with all sub elements. 42 00:03:05,800 --> 00:03:06,180 Right. 43 00:03:07,300 --> 00:03:12,280 And these are concatenated into it recursively up to the specified depth. 44 00:03:12,610 --> 00:03:14,050 And this is the depth here. 45 00:03:14,050 --> 00:03:16,590 So we can specify the depth here. 46 00:03:16,600 --> 00:03:18,010 I'm just going to put it here. 47 00:03:18,370 --> 00:03:19,480 I'm going to do it like this. 48 00:03:19,480 --> 00:03:24,610 I'm just going to of look one more time so you will be able to see that this is not working. 49 00:03:24,610 --> 00:03:24,940 Right. 50 00:03:25,990 --> 00:03:37,310 And now I will see depth of two, for example, and these should do the trick and I should have a console 51 00:03:37,310 --> 00:03:38,200 to save it. 52 00:03:39,040 --> 00:03:39,680 There you go. 53 00:03:39,850 --> 00:03:41,070 Now everything is sorted. 54 00:03:41,560 --> 00:03:41,940 Nice. 55 00:03:42,100 --> 00:03:45,460 So what about the let's put it here flat. 56 00:03:48,730 --> 00:03:54,620 And what about the flat method, right, flat map, OK? 57 00:03:54,940 --> 00:03:57,450 That's why I gave you this link so you can read more about it. 58 00:03:57,670 --> 00:04:04,180 And a flat map returns a new form by applying a giving callback function to each element of that array 59 00:04:04,480 --> 00:04:07,080 and then flattening the result by one level. 60 00:04:07,270 --> 00:04:07,670 Right. 61 00:04:08,230 --> 00:04:14,650 So it's doing a map because a map always returns a new area and it's doing a flat. 62 00:04:15,690 --> 00:04:17,430 Two by one level, right? 63 00:04:17,450 --> 00:04:24,600 I don't think that it will work on two or three levels, so it's doing flat and map in one go, it's 64 00:04:24,600 --> 00:04:29,310 identical to a map followed by a flap of one of depth of one. 65 00:04:29,340 --> 00:04:35,850 OK, so I'm going to give you one example, for example, how to find the positive numbers. 66 00:04:36,630 --> 00:04:37,350 Let's do this one. 67 00:04:37,360 --> 00:04:40,170 So it's identical to the map method, so don't worry about it. 68 00:04:40,350 --> 00:04:42,530 So you're not going to use this flat map too often. 69 00:04:42,620 --> 00:04:45,230 OK, so I'm going to create const numbers. 70 00:04:45,660 --> 00:04:51,210 This will be a that will have a negative and positive value. 71 00:04:51,210 --> 00:04:57,780 So minus one in one, then I have minus two into then I will have minus three and three, then I will 72 00:04:57,780 --> 00:05:00,740 have minus four and four, minus five five. 73 00:05:00,900 --> 00:05:05,520 So for each element I do have the minus version in the positive version. 74 00:05:05,790 --> 00:05:07,340 OK, so Cancela. 75 00:05:09,140 --> 00:05:11,130 Numbers very good. 76 00:05:11,510 --> 00:05:13,570 And I'm just going to pass the numbers away. 77 00:05:15,560 --> 00:05:16,230 There you go. 78 00:05:16,550 --> 00:05:22,220 Now, what I'm going to do, I'm going to use this flat map, although I don't have any levels here. 79 00:05:22,400 --> 00:05:24,270 I can have a different level if you want. 80 00:05:24,900 --> 00:05:25,170 Right. 81 00:05:25,370 --> 00:05:27,110 But that's idea here. 82 00:05:27,120 --> 00:05:29,960 I'm just going to create a positive const. 83 00:05:32,720 --> 00:05:39,440 Positive number, and I told you, this is working, so numbers, not flat map. 84 00:05:40,770 --> 00:05:51,330 Good, and I will say no here, an error function and we will see a return if the number is one is if 85 00:05:51,330 --> 00:05:56,280 it's great, if it's smaller than zero, then what I want to do, I will use the term every operator, 86 00:05:56,520 --> 00:05:59,160 then return me and Mary. 87 00:05:59,530 --> 00:06:02,190 Otherwise, give me back the number. 88 00:06:03,400 --> 00:06:03,860 Of that. 89 00:06:04,470 --> 00:06:12,300 So this should create a new map, I mean new array for us and store it in this positive number. 90 00:06:12,320 --> 00:06:20,820 So if I do cancel that log positive number, then I should be able to see one, two, three, four and 91 00:06:20,820 --> 00:06:22,860 five all the positive values there. 92 00:06:23,130 --> 00:06:23,750 There you go. 93 00:06:25,060 --> 00:06:31,030 So we used ternary operator here, so this is the same as if we say if no smallholdings you were, then 94 00:06:31,030 --> 00:06:32,410 don't give me anything else. 95 00:06:32,560 --> 00:06:35,570 Give me this number, the number that is from the array. 96 00:06:35,820 --> 00:06:36,190 Right. 97 00:06:36,940 --> 00:06:37,300 Good. 98 00:06:38,120 --> 00:06:38,930 That's pretty much it. 99 00:06:39,190 --> 00:06:40,600 Now, let's do 100 00:06:43,060 --> 00:06:52,510 Treme starred in Treme and these are on strings. 101 00:06:53,740 --> 00:07:04,930 OK, so let first name just do this with me and make this a couple of spaces there and say Samuell very 102 00:07:04,930 --> 00:07:15,860 good lad, last name and live like this Jackson and make a couple of spaces and there you go. 103 00:07:15,880 --> 00:07:16,600 So we have. 104 00:07:18,050 --> 00:07:27,650 Spaces before and spaces after here, so the we can use dream, start and end to get rid of these empty 105 00:07:27,650 --> 00:07:28,190 spaces. 106 00:07:28,220 --> 00:07:30,180 So how we can do this pretty much easy. 107 00:07:30,620 --> 00:07:33,400 So I'm just going to cause a lot and you will see the difference. 108 00:07:35,030 --> 00:07:39,950 Template literals, my full name is, and we're going to see. 109 00:07:41,230 --> 00:07:41,770 First. 110 00:07:44,880 --> 00:07:50,610 And I'm going to give a little oops, not for we shouldn't have a dollar sign last name. 111 00:07:50,760 --> 00:07:51,450 There you go. 112 00:07:52,460 --> 00:07:56,970 Save it there you have the output, here you have, but you don't see the end. 113 00:07:56,990 --> 00:07:58,410 I'm just going to put that at the end. 114 00:07:58,490 --> 00:08:02,540 Right now, you see that and let's make this little bit bigger. 115 00:08:02,870 --> 00:08:03,700 There you go. 116 00:08:03,710 --> 00:08:08,700 So my full name is Space Samuel, then Jackson, then space in the end. 117 00:08:09,090 --> 00:08:11,450 OK, so what are we going to do now? 118 00:08:11,750 --> 00:08:16,850 I'm just going to say first name and I'm going to save it. 119 00:08:17,030 --> 00:08:20,450 Whatever changes I made in the first name, back in the same variable. 120 00:08:20,450 --> 00:08:20,800 Right. 121 00:08:20,810 --> 00:08:26,060 Because it's lit, it's going to let us do this first name that. 122 00:08:27,770 --> 00:08:29,930 So what we need to trim the trim to start. 123 00:08:31,710 --> 00:08:32,350 Very good. 124 00:08:32,370 --> 00:08:40,830 And last name, I'm going to say your last name, not cream, and because what we want to do, we want 125 00:08:40,830 --> 00:08:45,060 to Treme start here from first name in Treme, the end from the last name. 126 00:08:45,430 --> 00:08:48,510 OK, now let's do the same thing. 127 00:08:51,000 --> 00:08:51,540 There you go. 128 00:08:51,780 --> 00:08:54,250 My full name is Samuel Jackson. 129 00:08:54,270 --> 00:08:54,990 We don't see that. 130 00:08:54,990 --> 00:08:55,790 Empty spaces. 131 00:08:56,280 --> 00:08:57,110 Very good. 132 00:08:58,380 --> 00:09:01,290 Last thing I want to discuss today is from entries. 133 00:09:02,610 --> 00:09:05,610 OK, so we're going to create const. 134 00:09:07,500 --> 00:09:16,850 User names and with the user names, this will be unary, right, and inside we will have multiple arrays. 135 00:09:16,980 --> 00:09:18,150 And I'm going to say, Rick. 136 00:09:19,450 --> 00:09:20,220 Let's put it here. 137 00:09:23,360 --> 00:09:24,640 Australia, very good. 138 00:09:24,810 --> 00:09:33,960 Now we have another story with two items inside, and I will say, Tom here, let's say here USA, then 139 00:09:33,960 --> 00:09:41,420 I will have another Arae say Edwyn in let's say Brazil. 140 00:09:42,660 --> 00:09:44,550 Then I will say Jason. 141 00:09:45,330 --> 00:09:48,720 Oops, I forgot to put it in a break in. 142 00:09:48,720 --> 00:09:49,650 Jason is from where? 143 00:09:49,980 --> 00:09:50,550 New Zealand. 144 00:09:56,340 --> 00:09:57,300 Let's close this one. 145 00:09:57,900 --> 00:10:05,270 OK, so a lot of the user names, user names, very good. 146 00:10:05,580 --> 00:10:12,900 They have so we have array for different arrays inside and we have two items in each array. 147 00:10:13,120 --> 00:10:20,370 OK, so what we can do with object form entries, remember, we have done the object. 148 00:10:22,710 --> 00:10:24,810 Let me just show you real quick. 149 00:10:27,710 --> 00:10:36,080 Where was it, lecturer six Here it is, object entry's object values object is we do this in the lecture 150 00:10:36,080 --> 00:10:36,360 six. 151 00:10:36,550 --> 00:10:39,490 If you haven't watch it, that's going to be pretty much similar. 152 00:10:39,500 --> 00:10:41,330 So we need to use the object that. 153 00:10:44,760 --> 00:10:46,920 So now let's do this so cost. 154 00:10:49,970 --> 00:10:55,940 User names object and I will see object. 155 00:10:57,110 --> 00:10:58,550 That from. 156 00:11:00,180 --> 00:11:02,380 Entries in inside. 157 00:11:02,400 --> 00:11:11,400 I'm going to pass the usernames, very cool, let's cancel the user names, object and see what will 158 00:11:11,400 --> 00:11:11,800 happen. 159 00:11:12,630 --> 00:11:13,270 Wow. 160 00:11:13,410 --> 00:11:15,870 Now I do have an. 161 00:11:16,970 --> 00:11:25,620 Object in that object have key value pairs, Rick, in Australia, these are coming from the inside. 162 00:11:25,880 --> 00:11:28,520 So what is this? 163 00:11:29,460 --> 00:11:36,180 From and she's doing so, he transforms array of key value pairs to an object with key properties and 164 00:11:36,180 --> 00:11:36,660 values. 165 00:11:37,720 --> 00:11:40,610 Koula, look, it is it looks very nice. 166 00:11:41,110 --> 00:11:41,970 So there you go. 167 00:11:41,980 --> 00:11:47,650 Now, you have a lot of things here, flat, flat, map, trim, start trim and from entries. 168 00:11:47,650 --> 00:11:51,250 And please read it a little bit if you want about the flat method. 169 00:11:51,580 --> 00:11:57,460 And it's pretty much the same as Matmata plus flat of that one. 170 00:11:58,030 --> 00:11:58,390 Right. 171 00:11:58,810 --> 00:12:02,740 But more efficient when calling those two methods, if separately. 172 00:12:02,740 --> 00:12:04,310 So it will be more efficient. 173 00:12:04,330 --> 00:12:06,690 OK, now we have done this. 174 00:12:07,060 --> 00:12:07,900 Don't worry about it. 175 00:12:08,230 --> 00:12:09,460 There are a couple of examples. 176 00:12:09,460 --> 00:12:11,800 I want you to look at it and there you go. 177 00:12:12,810 --> 00:12:17,580 So the last thing that I want to discuss is try and catch block, so we already have done try and catch 178 00:12:17,580 --> 00:12:18,170 a block, right. 179 00:12:18,510 --> 00:12:21,470 But there is a little bit difference here in Austin. 180 00:12:21,600 --> 00:12:23,100 And let me just show it to you. 181 00:12:23,400 --> 00:12:24,480 So try. 182 00:12:25,930 --> 00:12:26,920 And catch. 183 00:12:28,100 --> 00:12:35,210 Now, remember that we did try and catch you before in here, we need to passing a parameter like or 184 00:12:35,210 --> 00:12:38,270 argument the error and we doubt this. 185 00:12:38,270 --> 00:12:42,220 If we are not doing this, it will throw us an error. 186 00:12:42,230 --> 00:12:43,730 So error happened. 187 00:12:44,900 --> 00:12:45,250 Oops. 188 00:12:48,400 --> 00:12:51,570 And we can also bring up the error as well. 189 00:12:53,160 --> 00:13:07,000 Nice, and here comes all that log tri blog will be executed right now. 190 00:13:07,080 --> 00:13:07,970 Let's go back here. 191 00:13:08,310 --> 00:13:11,130 So Trappe block will be executed no matter what. 192 00:13:11,290 --> 00:13:13,290 So we're trying some piece of code here. 193 00:13:13,770 --> 00:13:16,590 And if there is an error here, I can throw an error. 194 00:13:19,250 --> 00:13:26,420 OK, then it happened, and it gives us the Arabic, right, but yes, then what we can do, we can 195 00:13:26,420 --> 00:13:27,590 skip this parameter here. 196 00:13:27,590 --> 00:13:28,260 We don't need it. 197 00:13:28,550 --> 00:13:29,930 This was before Houston. 198 00:13:31,070 --> 00:13:34,400 And let's say before is then. 199 00:13:34,700 --> 00:13:35,300 Now. 200 00:13:38,180 --> 00:13:41,300 Try and catch without. 201 00:13:42,840 --> 00:13:45,090 Error parameter. 202 00:13:46,680 --> 00:13:48,160 Now, I'm just going to copy this. 203 00:13:48,180 --> 00:13:50,210 So before this was not possible. 204 00:13:51,570 --> 00:13:56,370 So what we can do, we can get rid of that parameter there ever happened. 205 00:13:57,150 --> 00:13:58,110 And it's. 206 00:14:00,030 --> 00:14:00,930 It's working. 207 00:14:03,060 --> 00:14:03,540 There you go. 208 00:14:03,610 --> 00:14:05,950 Ever happen and it's working because we're throwing the air there. 209 00:14:06,180 --> 00:14:07,100 So there you go. 210 00:14:07,110 --> 00:14:08,280 That's the only difference. 211 00:14:08,490 --> 00:14:11,120 So we can catch errors without ever even here. 212 00:14:11,370 --> 00:14:12,800 We don't need to pass the error. 213 00:14:12,810 --> 00:14:13,180 Right. 214 00:14:13,380 --> 00:14:14,740 That's the whole thing. 215 00:14:15,120 --> 00:14:20,460 So, yeah, now some of the things are very easy for you because we have done it before. 216 00:14:20,460 --> 00:14:22,490 So this was before you stand now. 217 00:14:22,530 --> 00:14:24,210 This is in. 218 00:14:25,380 --> 00:14:25,890 Yes. 219 00:14:26,130 --> 00:14:27,320 Then oops. 220 00:14:28,590 --> 00:14:31,770 Try and catch without error parameter. 221 00:14:31,770 --> 00:14:32,180 Nice. 222 00:14:32,430 --> 00:14:33,160 So there you go. 223 00:14:33,450 --> 00:14:36,270 Well I will see you in the next one.