WEBVTT

00:01.120 --> 00:06.460
In this lecture, we're going to be talking about new data structures in ethics, which are maps and

00:06.460 --> 00:12.460
sets, those new data structures can be very useful and helpful in many real world situations.

00:12.940 --> 00:18.370
At first I'm going to introduce you map actually maps to our data as key value pairs.

00:18.820 --> 00:24.850
And one of the most important things regarding maps is that we're able to store any data types as keys

00:24.850 --> 00:25.450
and values.

00:26.650 --> 00:27.070
All right.

00:27.340 --> 00:34.730
Let's demonstrate how to create maps, syntactically create variable and college map data.

00:35.480 --> 00:38.980
Actually, we need to create maps using construct annotation.

00:39.310 --> 00:44.350
For that, we have to use new operator and that the keyword map with capital letter.

00:47.080 --> 00:52.240
Let's run it in council and see what looks like right map data.

00:54.660 --> 00:56.700
Reload, and here it is.

00:57.630 --> 01:04.150
So the first thing that we see here is Sise, which actually is a prop. and it gives us the size of

01:04.150 --> 01:04.520
a map.

01:04.950 --> 01:08.050
I mean, that it indicates the number of key value pairs.

01:08.760 --> 01:11.840
It's actually like the length property of an array.

01:13.220 --> 01:18.420
If we drop down, underscore, underscore, Proteau, underscore, underscore, will find here the methods

01:18.440 --> 01:23.900
which we are able to use with maps, one of the methods that you see here is set.

01:24.500 --> 01:30.800
So at first I'm going to use it actually set method allows us to insert data into a map.

01:31.340 --> 01:43.850
So let's right map data dot set and then write inside parentheses as a key name and then as value John.

01:46.370 --> 01:54.620
Reload and see that item is added in this case, both key and value is represented as drinks, but instead

01:54.620 --> 02:00.470
of drinks, we're able to use numbers, boolean values, arrays, objects and even functions.

02:01.190 --> 02:04.940
Let's add as a key boolean value right.

02:04.950 --> 02:08.720
Map data that set right here through.

02:10.070 --> 02:11.540
And then the value, yes.

02:12.830 --> 02:17.600
Also, let's create an object, right, cost, constant object.

02:19.030 --> 02:20.980
And then added as key.

02:22.230 --> 02:26.490
Right, again, map data that set object.

02:27.520 --> 02:30.340
And then as a value right person.

02:32.360 --> 02:37.850
Reload the page and you said that we have here our newly added key value pairs.

02:38.830 --> 02:44.890
All right, in order to get the size of map, we just need to use size property using dot notation,

02:45.430 --> 02:50.560
let's run it in council duplicate and write your dot size.

02:52.800 --> 03:00.330
So here we have three, because MAP actually contains three items, so using that method is one of the

03:00.330 --> 03:01.890
ways to add items to map.

03:02.340 --> 03:10.380
But we can initialize map with data by passing an array, which itself will include other arrays with

03:10.380 --> 03:11.250
key value pairs.

03:12.060 --> 03:13.190
Let's see how it works.

03:14.010 --> 03:21.920
Open square brackets that create array with key turn and with value again.

03:22.020 --> 03:25.200
Right turn then create another array.

03:26.930 --> 03:28.100
Right is married.

03:29.820 --> 03:31.440
And the value false.

03:33.180 --> 03:37.590
Reload and you see, we have your newly added items.

03:38.760 --> 03:45.360
All right, that's actually how we add items to map and now let's see how we can get access on them

03:45.810 --> 03:46.210
for that.

03:46.230 --> 03:48.500
There is one of the methods which is called Get.

03:49.230 --> 03:52.740
So in order to get item, for example, name, we have to.

03:52.740 --> 03:53.100
Right.

03:53.970 --> 03:58.410
Cancel that log map data that get.

03:59.910 --> 04:02.070
And then the name.

04:04.830 --> 04:13.020
Reload and we have value of nine key, which is John, OK, in order to check if there exists the specified

04:13.020 --> 04:16.000
key, we can use one of the methods which is called has.

04:16.740 --> 04:21.720
So if the key exists, it returns true value, otherwise it returns false.

04:22.350 --> 04:25.470
Let's check in from updater contains object key.

04:25.470 --> 04:27.030
So write that log.

04:28.230 --> 04:30.510
Map data that has.

04:31.480 --> 04:40.650
And then insert here, object, reload, and we have to because map contains the key keep all right,

04:41.350 --> 04:48.180
besides the hazmat that we had delete, which actually allows us to delete from a single key value pairs.

04:48.760 --> 04:54.490
So, for example, if we write map data, dot delete.

04:57.220 --> 05:00.550
And indicate here one of the keys, for example, said.

05:01.510 --> 05:09.580
And as a result, you will see that with its value is removed from that, OK, in order to delete the

05:09.580 --> 05:14.960
entire data from up, we can use Carlier method, which actually will make our map empty.

05:15.430 --> 05:17.050
So that's right.

05:17.220 --> 05:19.690
Mark Dot Carlier.

05:22.120 --> 05:25.380
Then reload and I see that map is empty.

05:26.550 --> 05:28.950
All right, let's delete clear method.

05:31.410 --> 05:37.140
And if we check on the score on the score, Proteau underscore and the score we will find here for each

05:37.140 --> 05:42.240
array helper method, and I would like to note that this is the only array, Harpur, which we are able

05:42.240 --> 05:43.220
to use with maps.

05:44.160 --> 05:49.840
So that's the latest council that logs and use, for example, with map data.

05:50.350 --> 05:50.790
Right.

05:50.790 --> 05:55.340
Map DataDot forage as a first parameter.

05:55.350 --> 06:01.980
We're going to place your value because at first each method will return values of keys.

06:03.090 --> 06:06.930
And then as the second parameter that insert here key.

06:09.830 --> 06:10.820
Run in council.

06:12.860 --> 06:15.500
Value add key.

06:17.140 --> 06:25.210
Reload and we have here keys and values there was not that we were expecting, OK, besides for a chopper

06:25.210 --> 06:27.760
we can use for of statement with maps.

06:28.480 --> 06:32.350
So that's comments for each method out and then.

06:32.620 --> 06:33.700
Right for.

06:35.510 --> 06:44.420
Suppose that we want to get kids from app, so let's create let QI then use the keyboard of.

06:45.710 --> 06:50.900
In order to get all the kids from that, we have to use one of the methods of KNAB, which is called

06:50.900 --> 06:51.410
keys.

06:52.790 --> 06:55.070
So right up DataDot Keys.

06:57.900 --> 06:59.670
And that Iranian castle.

07:01.860 --> 07:03.450
Right here, keep.

07:05.020 --> 07:07.780
Let's reload the page and.

07:09.040 --> 07:15.670
You say that we have here are the keys from up in the same way we can get all the values, and for that

07:15.670 --> 07:18.580
we have to use other method, which is called values.

07:19.150 --> 07:21.460
So let's change your keys into a values.

07:23.740 --> 07:26.560
Also right value instead of key.

07:29.580 --> 07:30.180
Reload.

07:31.070 --> 07:33.200
And now we have the values.

07:34.850 --> 07:42.700
All right, if we want to get simultaneously keys and values, we can use another method which is at

07:42.710 --> 07:43.000
risk.

07:43.760 --> 07:46.100
So let's change values into entries.

07:47.280 --> 07:54.450
And also right here, instead of value array, because entries method actually returns key value pairs

07:54.450 --> 07:55.110
as a race.

07:56.170 --> 08:01.690
So let's reload and you see that we have a race which consists of key value pairs.

08:02.760 --> 08:07.710
If we don't want to get them as a race that simply we can distract you, then.

08:08.840 --> 08:17.420
So that's change arriving to key value right inside square brackets and also round them in Castle.

08:20.860 --> 08:25.360
Reload and we have now keys and values represented without a race.

08:26.530 --> 08:28.820
All right, it was all about maps.

08:28.840 --> 08:35.800
Let's go ahead and talk about another new data structure in Essex, which is set actually set holds

08:35.800 --> 08:36.940
values without keys.

08:36.940 --> 08:42.230
And mostly it's used in real world when we want to store all the unique values.

08:43.120 --> 08:44.240
Let's see what it means.

08:44.260 --> 08:46.510
I'm going to comment this code out.

08:48.400 --> 08:55.210
In order to create said, we have to use again construct a notation, let's create variable and call

08:55.210 --> 08:56.350
it set data.

08:58.270 --> 09:01.270
Then use new operator and right set.

09:03.750 --> 09:07.390
Run it in council in order to see what it actually looks like, right?

09:07.920 --> 09:08.250
Log.

09:09.270 --> 09:11.070
Set Theta.

09:13.380 --> 09:20.360
So, like Matt said, has size property as well, and if we drop down on the score on the score prior

09:20.410 --> 09:25.520
to underscore on the score, we will find here some methods that we have already seen with the map.

09:26.130 --> 09:32.400
But if you look at them carefully, you will notice that actually some of them are missing because they

09:32.400 --> 09:33.990
are not used with sets.

09:35.230 --> 09:40.530
All right, let's see how we can add items into that, we have two ways for doing that.

09:40.990 --> 09:43.290
The first one is to use add method.

09:44.080 --> 09:48.370
So if we write set data, dots add.

09:50.720 --> 09:51.980
With the value neek.

09:53.810 --> 09:54.740
That without.

09:56.500 --> 09:57.820
We will have here, Nick.

09:59.080 --> 10:05.350
Like it was in case of map, we can add as values, any data type, and you can test it on your own.

10:06.150 --> 10:13.210
The second method to add items is to place your inside parentheses array and then add as many items

10:13.210 --> 10:13.850
as we want.

10:14.770 --> 10:16.270
So that answer to your.

10:18.330 --> 10:20.160
John, that.

10:21.530 --> 10:21.950
San.

10:23.500 --> 10:25.780
Then, for example, false value.

10:27.470 --> 10:32.900
Also, place your object with property first name.

10:34.420 --> 10:34.840
Bob.

10:38.600 --> 10:44.900
And to the end, let's add here, John, once again and see what happens, reload.

10:46.290 --> 10:52.290
So we have here all the items that we have just added, but you notice that John is added here only

10:52.290 --> 10:57.450
once, that's because generally set stores only unique values.

10:58.680 --> 11:00.570
So if we check the size of that.

11:04.560 --> 11:07.140
Then we will get five.

11:08.250 --> 11:15.150
So actually, we have added six items, but because of that, we have repeated, John said, started

11:15.150 --> 11:18.660
only once, and that's why we have here five instead of six.

11:20.010 --> 11:28.530
All right, in case of sets we can use has the lead clear methods also right for a chopper, but I'm

11:28.530 --> 11:34.370
not going to waste time on that because they work in the exact same way as it was in case of maps.

11:35.520 --> 11:40.950
The last thing that I'm going to do is to use four of statement because it gives us a bit different

11:40.950 --> 11:41.420
results.

11:42.420 --> 11:48.890
So let's create for that let's value of such data.

11:49.910 --> 11:51.340
That values.

11:54.270 --> 11:56.490
That Romney town council.

12:02.280 --> 12:05.250
So if we revote, we will get values.

12:06.740 --> 12:11.270
The same will happen if we use your case method instead of values.

12:12.840 --> 12:16.110
And it happens because they actually said, doesn't have Keith.

12:17.850 --> 12:20.460
But if we use Andris method.

12:22.600 --> 12:23.650
Instead of kiss.

12:24.730 --> 12:30.140
Then we will get a raise and you see that each of these arrays contain duplicated values.

12:30.910 --> 12:36.690
Honestly, the cases of keys and interest methods are kind of weird, but that's the way how they work.

12:38.040 --> 12:44.310
All right, this was all about new data structures in year six maps and sets, I think both of them

12:44.310 --> 12:50.700
are very flexible and powerful data types, especially a map, and they can be used in many cases instead

12:50.700 --> 12:52.980
of objects and a rise in real world.

12:53.750 --> 12:57.600
Also, the key point is that they work in very simple white.

12:58.770 --> 13:00.300
OK, let's move on.
