Welcome back, ladies and gentlemen.
Today, we're going to talk about S10 features.
So this is ECMAScript 2019 and we have done a lot.
So today we're going to do flat and flat map methods, dream, start and trim and from entry's try and
catch block.
Now, let's start I'm going to give you this link to flat map so you can read more about it now.
Create lectured and linked in your link, this lecture in your index file.
And start with the first one with the flat.
OK, so what is a flat method?
So this method creates a new array with all separate elements concatenated into it, recursively up
to the specified depth.
OK, so for the first example, I'm going to create an array.
And I'm going to just show you what is happening, so I'm going to say a one, and this array will be
one, two, three, four, five and six.
OK, if I consolatory, you will just be able to see the entire.
So the flat method will not work on this array or it will work.
So even if I do a.
Not flat, you will see the same array back now if I create another array, let's say three, two,
and if I have nested array inside here, oops, not like that.
Let's say five and six.
Now I can use the flat method and look what is happening.
So first I'm just going to print out the.
The Ureta right, so we have this inside.
Good, we can see it, and if I use the flat method on top of it, it will flatten the array.
So it will give me the ostry back to as it was.
Let's make this one a little bit different.
Nice.
But what will happen if I have another level here and Yurie in inside a ternary 10 and 11?
Now if I see if I just save it, then you will be able to see that eight.
It's all all done, right?
One, two, three, four, five, six, eight, but 10 and 11, there's a separate array in.
Why is this happening?
Well, the flat method, if we just did we just put it like this without any parameter, then it will
go and flatten there, even if there is a one nested.
But there is when there is a multiple deep level nesting, then it will work only on two levels.
So this is a third level.
So what we can do, we can just create here.
We can just put here too, and that will sort it out.
But sometimes in order to be sure that you can put ten and yeah, it will do the same trick.
So that is the flat method.
So the flat method again creates a new array with all sub elements.
Right.
And these are concatenated into it recursively up to the specified depth.
And this is the depth here.
So we can specify the depth here.
I'm just going to put it here.
I'm going to do it like this.
I'm just going to of look one more time so you will be able to see that this is not working.
Right.
And now I will see depth of two, for example, and these should do the trick and I should have a console
to save it.
There you go.
Now everything is sorted.
Nice.
So what about the let's put it here flat.
And what about the flat method, right, flat map, OK?
That's why I gave you this link so you can read more about it.
And a flat map returns a new form by applying a giving callback function to each element of that array
and then flattening the result by one level.
Right.
So it's doing a map because a map always returns a new area and it's doing a flat.
Two by one level, right?
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
identical to a map followed by a flap of one of depth of one.
OK, so I'm going to give you one example, for example, how to find the positive numbers.
Let's do this one.
So it's identical to the map method, so don't worry about it.
So you're not going to use this flat map too often.
OK, so I'm going to create const numbers.
This will be a that will have a negative and positive value.
So minus one in one, then I have minus two into then I will have minus three and three, then I will
have minus four and four, minus five five.
So for each element I do have the minus version in the positive version.
OK, so Cancela.
Numbers very good.
And I'm just going to pass the numbers away.
There you go.
Now, what I'm going to do, I'm going to use this flat map, although I don't have any levels here.
I can have a different level if you want.
Right.
But that's idea here.
I'm just going to create a positive const.
Positive number, and I told you, this is working, so numbers, not flat map.
Good, and I will say no here, an error function and we will see a return if the number is one is if
it's great, if it's smaller than zero, then what I want to do, I will use the term every operator,
then return me and Mary.
Otherwise, give me back the number.
Of that.
So this should create a new map, I mean new array for us and store it in this positive number.
So if I do cancel that log positive number, then I should be able to see one, two, three, four and
five all the positive values there.
There you go.
So we used ternary operator here, so this is the same as if we say if no smallholdings you were, then
don't give me anything else.
Give me this number, the number that is from the array.
Right.
Good.
That's pretty much it.
Now, let's do
Treme starred in Treme and these are on strings.
OK, so let first name just do this with me and make this a couple of spaces there and say Samuell very
good lad, last name and live like this Jackson and make a couple of spaces and there you go.
So we have.
Spaces before and spaces after here, so the we can use dream, start and end to get rid of these empty
spaces.
So how we can do this pretty much easy.
So I'm just going to cause a lot and you will see the difference.
Template literals, my full name is, and we're going to see.
First.
And I'm going to give a little oops, not for we shouldn't have a dollar sign last name.
There you go.
Save it there you have the output, here you have, but you don't see the end.
I'm just going to put that at the end.
Right now, you see that and let's make this little bit bigger.
There you go.
So my full name is Space Samuel, then Jackson, then space in the end.
OK, so what are we going to do now?
I'm just going to say first name and I'm going to save it.
Whatever changes I made in the first name, back in the same variable.
Right.
Because it's lit, it's going to let us do this first name that.
So what we need to trim the trim to start.
Very good.
And last name, I'm going to say your last name, not cream, and because what we want to do, we want
to Treme start here from first name in Treme, the end from the last name.
OK, now let's do the same thing.
There you go.
My full name is Samuel Jackson.
We don't see that.
Empty spaces.
Very good.
Last thing I want to discuss today is from entries.
OK, so we're going to create const.
User names and with the user names, this will be unary, right, and inside we will have multiple arrays.
And I'm going to say, Rick.
Let's put it here.
Australia, very good.
Now we have another story with two items inside, and I will say, Tom here, let's say here USA, then
I will have another Arae say Edwyn in let's say Brazil.
Then I will say Jason.
Oops, I forgot to put it in a break in.
Jason is from where?
New Zealand.
Let's close this one.
OK, so a lot of the user names, user names, very good.
They have so we have array for different arrays inside and we have two items in each array.
OK, so what we can do with object form entries, remember, we have done the object.
Let me just show you real quick.
Where was it, lecturer six Here it is, object entry's object values object is we do this in the lecture
six.
If you haven't watch it, that's going to be pretty much similar.
So we need to use the object that.
So now let's do this so cost.
User names object and I will see object.
That from.
Entries in inside.
I'm going to pass the usernames, very cool, let's cancel the user names, object and see what will
happen.
Wow.
Now I do have an.
Object in that object have key value pairs, Rick, in Australia, these are coming from the inside.
So what is this?
From and she's doing so, he transforms array of key value pairs to an object with key properties and
values.
Koula, look, it is it looks very nice.
So there you go.
Now, you have a lot of things here, flat, flat, map, trim, start trim and from entries.
And please read it a little bit if you want about the flat method.
And it's pretty much the same as Matmata plus flat of that one.
Right.
But more efficient when calling those two methods, if separately.
So it will be more efficient.
OK, now we have done this.
Don't worry about it.
There are a couple of examples.
I want you to look at it and there you go.
So the last thing that I want to discuss is try and catch block, so we already have done try and catch
a block, right.
But there is a little bit difference here in Austin.
And let me just show it to you.
So try.
And catch.
Now, remember that we did try and catch you before in here, we need to passing a parameter like or
argument the error and we doubt this.
If we are not doing this, it will throw us an error.
So error happened.
Oops.
And we can also bring up the error as well.
Nice, and here comes all that log tri blog will be executed right now.
Let's go back here.
So Trappe block will be executed no matter what.
So we're trying some piece of code here.
And if there is an error here, I can throw an error.
OK, then it happened, and it gives us the Arabic, right, but yes, then what we can do, we can
skip this parameter here.
We don't need it.
This was before Houston.
And let's say before is then.
Now.
Try and catch without.
Error parameter.
Now, I'm just going to copy this.
So before this was not possible.
So what we can do, we can get rid of that parameter there ever happened.
And it's.
It's working.
There you go.
Ever happen and it's working because we're throwing the air there.
So there you go.
That's the only difference.
So we can catch errors without ever even here.
We don't need to pass the error.
Right.
That's the whole thing.
So, yeah, now some of the things are very easy for you because we have done it before.
So this was before you stand now.
This is in.
Yes.
Then oops.
Try and catch without error parameter.
Nice.
So there you go.
Well I will see you in the next one.