WEBVTT 00:02.010 --> 00:08.840 Welcome in this lecture, I'm going to talk about the full slice expressions, a full slice expression 00:08.850 --> 00:13.700 allows you to control the capacity of a return slice from a slice expression. 00:14.130 --> 00:17.040 Let me show you how it works and why you want to use it. 00:17.960 --> 00:25.100 Let's take a look at a simple expression first, I know you're already mastered this now let's take 00:25.100 --> 00:26.870 a look at our full size expression. 00:28.050 --> 00:33.980 A full glass expression has a third index called the cap, or more formally, the max. 00:34.620 --> 00:41.160 So using a full slice expression, you can slice a slice and at the same time, you can limit the capacity 00:41.160 --> 00:43.770 of the return slice from this slice expression. 00:44.730 --> 00:46.440 Let's take a look at some examples. 00:47.860 --> 00:50.470 Let's say you have a slice such as this one. 00:51.390 --> 00:57.600 That creates this slice, I'm going to put the sliceable variable here so you can understand what's 00:57.600 --> 00:58.390 going on better. 00:59.130 --> 01:03.750 Now, let's slice it by starting from its first index up to its third element. 01:04.990 --> 01:08.740 May do so, it returns a new slice that looks like this. 01:11.610 --> 01:16.020 The length is three and the capacity is four, so far so good. 01:16.560 --> 01:21.060 Now let's use a full glass expression to limit the capacity like this. 01:22.160 --> 01:23.240 OK, here it is. 01:23.450 --> 01:25.540 Let's check out the slicers capacity now. 01:26.570 --> 01:30.430 Think of the capacity position as the element position in the back injury. 01:31.040 --> 01:32.150 Here it is three. 01:32.150 --> 01:35.300 So it returns a slice with the capacity of three elements. 01:35.870 --> 01:41.750 It hides the last element from the return slice me, limit the capacity even further. 01:42.050 --> 01:48.980 To do that, I also need to change the stopping position is because the stopping position can't be greater 01:48.980 --> 01:50.330 than the capacity position. 01:50.900 --> 01:55.880 Now the slice cannot see the rest of the begging Gary's elements after the second element. 01:56.480 --> 01:58.520 Let's limit the capacity even further. 01:58.910 --> 02:04.040 So now the slice can only see the back in Gary's first element, not the rest of it. 02:04.730 --> 02:08.230 Now, let's take a look at this slice expression here. 02:08.240 --> 02:14.870 I set the cup, the position to three, but the capacity of the slice becomes to speak because for this 02:14.870 --> 02:18.170 slice, there are only two elements in Specking array. 02:19.590 --> 02:27.120 Here I increase the starting index to two, so the slices capacity becomes one is because the slice 02:27.120 --> 02:28.710 can only see this element. 02:31.290 --> 02:34.030 Here are increment the capacity position to four. 02:34.770 --> 02:39.570 So the fourth element of the begging injury becomes visible to the slice for the slice. 02:39.990 --> 02:43.980 There are two elements in this injury, so its capacity becomes too. 02:45.420 --> 02:46.920 OK, one last example. 02:48.630 --> 02:56.250 Here I said all the indexes to for so the slice becomes empty now, so when you add an element to this 02:56.250 --> 03:00.180 slice, the apan function will allocate a new era for its. 03:01.590 --> 03:02.830 OK, enough theory. 03:03.390 --> 03:05.520 Now, let's take a look at that cold example. 03:08.220 --> 03:09.600 Let's create an insidious. 03:14.170 --> 03:14.920 Lima printed. 03:17.960 --> 03:24.260 As you guessed, this lies its length and capacity are for the first two elements of the slides are 03:24.260 --> 03:27.110 old numbers and the rest are even numbers. 03:27.650 --> 03:30.610 Let's say I want to slice it for the odd numbers. 03:31.310 --> 03:33.440 Let me also show you the old slice. 03:35.410 --> 03:42.370 As you can see, the numbers and the old slices are sharing the same baking array, the old slice has 03:42.370 --> 03:45.410 two elements and there are two more elements in the back injury. 03:46.120 --> 03:49.330 Let me open two more odd numbers to the old slice. 03:51.510 --> 03:54.960 Doing so overwrites the normalises back injury as well. 03:55.230 --> 03:57.120 So how can I prevent this problem? 03:57.900 --> 04:01.080 Well, I can use a full sized expression like this. 04:02.710 --> 04:08.800 Now, it doesn't override the begging aura of the numb slice, it's because the numbers and the slices 04:08.800 --> 04:10.450 have different back injuries now. 04:11.400 --> 04:16.230 So why do they have different arrays, please powers the video and try to guess. 04:21.490 --> 04:25.540 OK, is because here I limit the capacity of the old slice, right? 04:26.260 --> 04:27.880 Let me comment about this aband. 04:29.200 --> 04:35.950 So before that happened, they were sharing the same array, however old slices capacity was two, so 04:35.950 --> 04:38.130 it didn't have any remaining capacity. 04:38.170 --> 04:39.340 It was already full. 04:39.610 --> 04:41.350 So I expanded to it. 04:41.560 --> 04:46.390 Here, the apan function calculated that there wasn't enough capacity in the slice. 04:46.540 --> 04:48.460 So it has allocated a new array. 04:48.790 --> 04:53.680 So unless you want to override the old slice, you should use a full glass expression. 04:53.680 --> 04:56.880 As in here, by the way, I can refactor this code. 04:57.310 --> 04:59.290 Let me add this up and call here. 05:00.240 --> 05:02.220 And let me remove this up and call here. 05:04.680 --> 05:11.370 All right, whether it still works here, first it returns a slice with a capacity of two, then appending 05:11.370 --> 05:14.010 to it returns a new slice with a new back injury. 05:14.520 --> 05:18.110 Let me also add two more, even numbers to the numbers slice. 05:19.080 --> 05:25.010 Here I say the result to a new variable, so the return slice doesn't override the numskulls. 05:26.790 --> 05:32.550 I didn't use a full glass expression here, however, that even Slice has a new back injury despite 05:32.550 --> 05:32.970 of that. 05:33.300 --> 05:35.040 But why this past video? 05:35.040 --> 05:36.000 And try to guess. 05:40.800 --> 05:44.010 Well, it's because the numskulls is already full. 05:44.480 --> 05:45.810 It's cuppers these four. 05:46.020 --> 05:53.100 So when I point to it, the function allocates a new era and returns a slice that references to that 05:53.100 --> 05:53.620 new era. 05:53.850 --> 05:56.490 That's why it doesn't change the num slice. 05:56.550 --> 05:59.460 So you don't always need the use of full slice expression. 06:00.180 --> 06:00.710 All right. 06:00.720 --> 06:01.600 That's all for now. 06:01.620 --> 06:02.500 Thank you for watching. 06:02.520 --> 06:03.480 See in the next picture.