WEBVTT 00:00.390 --> 00:07.680 Welcome in this lecture, I'm going to show you a rarely known feature of Galeras called the Key Elements. 00:08.550 --> 00:14.130 This is also one of the features of slicers, but I'm going to talk about it in the next section, not 00:14.130 --> 00:14.400 here. 00:14.800 --> 00:20.160 OK, sometimes this feature can be useful and only a handful of people are aware of it. 00:20.700 --> 00:24.580 Even the most experienced golfers are unaware of this feature. 00:25.170 --> 00:26.670 So what is a key element? 00:26.850 --> 00:27.840 Let's check it out now. 00:28.620 --> 00:34.830 Let's say you want to create a program that prints the cryptocurrency exchange ratios, for example, 00:34.830 --> 00:39.000 value ask what is the current exchange ratio of each area? 00:39.540 --> 00:42.420 It will display its ratio against the bitcoin. 00:42.610 --> 00:45.800 OK, it will just do a simple conversion. 00:46.620 --> 00:49.710 So to do that, I'm going to declare an array variable. 00:51.800 --> 00:58.460 This will create an area like this one, so according to this area, one yttrium is half of Bitcoin. 00:58.670 --> 01:03.230 OK, the other elements represent different cryptocurrency ratios. 01:04.180 --> 01:07.720 OK, now I'm going to show you the indexes of these elements. 01:09.430 --> 01:16.240 You know this already, but what if I tell you that you can use indexes inside the elementalist of this 01:16.240 --> 01:16.560 area? 01:16.580 --> 01:18.190 Literal, let me show you. 01:19.290 --> 01:25.680 Now, I'm going to type the first element with its index like this and the second element like this 01:26.340 --> 01:31.920 and the last element, this area literal is equal to the previous array, litoral. 01:32.230 --> 01:35.430 So it creates the same array as you can see below. 01:36.120 --> 01:37.800 Let me show you how they work. 01:38.580 --> 01:41.470 These highlighted parts are the key elements. 01:42.090 --> 01:43.620 So this is an area literal. 01:43.830 --> 01:47.640 So each key here corresponds to an index of the array. 01:48.210 --> 01:55.130 As you can see, zero equals two index zero and key one equals to index one. 01:55.530 --> 01:59.690 And the last key two equals to index two and so on. 02:00.300 --> 02:04.290 But this doesn't prove you the real power of the key elements. 02:04.320 --> 02:04.700 Right. 02:05.540 --> 02:08.540 Let's take a look at a better example here. 02:08.580 --> 02:11.040 I have changed the order of the keys. 02:11.520 --> 02:15.060 As you can see, this creates the same as before. 02:15.600 --> 02:17.520 Let's take a look at the indexes again. 02:17.850 --> 02:20.910 The index of the first key element here is one. 02:21.540 --> 02:24.560 So this element becomes the second element of the array. 02:25.390 --> 02:28.310 And the index of the second key element is zero. 02:28.780 --> 02:31.960 So this element becomes the first element of the array. 02:32.880 --> 02:40.080 And lastly, the index of the last element is two, so it becomes the last element of the array, as 02:40.080 --> 02:40.750 you can see. 02:40.800 --> 02:46.650 You can put elements into any index position inside the area by using key elements. 02:47.370 --> 02:47.790 Cool. 02:49.240 --> 02:54.610 Let me show you one more thing, what will happen then use a key element like this. 02:55.870 --> 03:04.180 This will create an area such as this one here, I'm telling God that a six to four area with a length 03:04.180 --> 03:12.550 of three, then I'm saying it to put these elements to the last index, go initializes the first items 03:12.550 --> 03:18.900 to their zero values because it doesn't know their values, because we didn't give them to go. 03:19.170 --> 03:21.900 OK, let's take a look at another example. 03:22.480 --> 03:26.560 What happens if I specify the length using an ellipsis? 03:27.220 --> 03:27.910 Let me show you. 03:30.240 --> 03:37.450 This will create an error like this, as you can see, it creates an error with six elements automatically. 03:38.010 --> 03:42.980 This is because Vango sees that the index of the key element is five. 03:43.470 --> 03:47.400 It thinks that the length of this array should be six. 03:48.060 --> 03:49.580 Let me show you one last thing. 03:50.070 --> 03:52.700 This time will be a more complicated example. 03:52.890 --> 03:54.020 So pay attention. 03:54.750 --> 03:56.970 Look at this area literal here. 03:56.970 --> 04:00.660 I've used key elements and unquit elements together. 04:00.840 --> 04:01.180 Right. 04:01.680 --> 04:08.650 Can you guess what will be the lengths of this error and where Gore will put these elements, pause 04:08.680 --> 04:11.840 the video and think about it for a minute or so, OK? 04:16.610 --> 04:22.920 All right, let me show you go finds the lowest indexed element first, which is this one. 04:23.720 --> 04:24.890 So go first. 04:24.890 --> 04:30.140 Put this element to the first index is because its index is zero. 04:31.070 --> 04:35.600 Dango looks for the second key element, which is this one five. 04:36.520 --> 04:44.710 Since there are no Ankit elements before, that goal will add zero value elements up to five like this, 04:45.460 --> 04:49.620 and then it adds this key element to the fifth index. 04:50.320 --> 04:53.980 And lastly, gold will look for on key elements. 04:54.590 --> 04:57.130 Here is only one on key elements, right? 04:57.490 --> 04:59.020 This one, 2.5. 04:59.590 --> 05:07.960 As you can see, gold puts this element to the index is because an iron key element gets its index from 05:07.960 --> 05:09.460 the last key element. 05:09.790 --> 05:14.010 OK, here, the last key elements index is five. 05:14.260 --> 05:15.910 So these are key elements. 05:15.910 --> 05:20.140 Index becomes six, which is right after the last Ankit element. 05:21.010 --> 05:23.350 Let's take a look at an example in the coating, Ed.. 05:23.600 --> 05:28.970 We're going to build a very simple program that will print the cryptocurrency exchange ratios from Array. 05:29.650 --> 05:31.580 First, I'm going to declare an array. 05:32.050 --> 05:35.850 Let's say this array stores to exchange ratios for bitcoin. 05:36.310 --> 05:41.640 So one bitcoin is twenty five that five yttrium and one twenty that five one chain. 05:42.370 --> 05:45.210 These are the names of the cryptocurrency by the way. 05:45.760 --> 05:46.300 All right. 05:46.330 --> 05:48.580 Now let's print them first. 05:48.580 --> 05:53.500 I'm going to print yttrium ratio like this, then I'm going to print one chain ratio. 05:54.100 --> 05:58.840 As you can see here, I'm used to magic numbers, but this is not good. 05:58.840 --> 06:00.160 It is difficult to read. 06:00.160 --> 06:00.520 Right. 06:01.120 --> 06:05.230 So let's refactor this program and let's use the key elements instead. 06:06.050 --> 06:12.890 First, I'm going to declare two constants for yttrium and one change here, I initialize them using 06:12.890 --> 06:13.370 IETA. 06:14.150 --> 06:20.000 If you don't know what Ayata is done, please watch the IETA lecture in the Constants section. 06:20.150 --> 06:25.040 OK, now I'm going to use constants instead of typing the indexes manually. 06:25.730 --> 06:32.940 Let me first change these elements index to constants since this constant equals to zero. 06:33.050 --> 06:35.800 So these elements index also becomes zero. 06:36.200 --> 06:42.620 And next I'm going to define the second elements index as W and W and equals one. 06:42.740 --> 06:46.430 So does the index of this element almost ready now? 06:46.430 --> 06:52.280 Instead of getting the rates by using the magic numbers, I'm going to use my newly declared constants 06:52.280 --> 06:53.990 here as a first. 06:54.000 --> 07:03.130 I'm going to change in zero to H and then I'm going to change one here to w an OK, let's run its cool. 07:03.140 --> 07:05.510 It prints the same output as before. 07:05.930 --> 07:12.080 However, notice that this program is better compared to its previous version because it's more readable. 07:12.230 --> 07:12.580 Right. 07:13.500 --> 07:19.110 Because I'm using very different names like ETA and W and instead of zero and one. 07:19.920 --> 07:22.200 OK, they can print all the elements. 07:23.180 --> 07:30.920 OK, limerence, OK, here, I can change the order of the elements like this limerence again, as you 07:30.920 --> 07:33.080 can see, the output is still the same. 07:33.620 --> 07:38.630 This is because the key elements define the index position here. 07:39.080 --> 07:43.590 The order of the elements that I'm going to type or I have typed here is important. 07:43.940 --> 07:45.590 Let me show you one more example. 07:46.190 --> 07:49.910 Let's say I'm planning to start 10 different currencies here. 07:50.860 --> 07:55.320 To do that, I can just start this constant from nine instead of zero like this. 07:55.930 --> 08:02.160 So the first element will be in the ninth index and the second element will be in this eight index and 08:02.200 --> 08:02.680 so on. 08:03.770 --> 08:05.900 So this will make the area larger. 08:06.440 --> 08:08.870 It's because now the largest index is nine. 08:09.410 --> 08:10.130 Let me show you. 08:11.250 --> 08:15.760 As you can see, all the elements, but last two to have zero values, right? 08:16.560 --> 08:19.870 Let me add one more cryptocurrency here, for example. 08:21.850 --> 08:28.120 Then I need to add it to the area as well like this, let's say its ratio is 20, so I'm going to type 08:28.120 --> 08:28.780 20 here. 08:29.690 --> 08:35.360 Let me run it one more time, as you can see now, ISIS is in the seventh index. 08:36.540 --> 08:40.950 All right, that's all for now, but no worries in the upcoming lectures. 08:40.980 --> 08:43.260 We're going to use the key elements again and again. 08:43.710 --> 08:45.740 So see in the next lecture our.