WEBVTT 00:05.750 --> 00:10.860 In this video you're going to explore some other new Array methods in iOS 6. 00:10.940 --> 00:15.290 So you're going to create an array X and then carry out. 00:15.440 --> 00:23.000 If you activity's using those new methods so you can notice that we've got an empty element inside X 00:23.120 --> 00:25.130 which I put there on purpose. 00:26.120 --> 00:29.290 So we're using the cons declaration. 00:29.660 --> 00:35.100 But this is fine if you want to change things inside X right. 00:35.120 --> 00:39.510 So this is very similar to when you are changing properties inside an object. 00:39.530 --> 00:44.000 You can still do that to a constant object. 00:44.000 --> 00:44.300 All right. 00:44.300 --> 00:51.110 So now let's find the first element which is greater than six. 00:51.250 --> 00:59.200 So to do that you would need to use a method called Find. 00:59.200 --> 01:06.940 So this method will take us a problem is that a function which will test the elements of the array. 01:07.570 --> 01:16.840 So this function will return a boolean and the first elements which fulfills the condition is going 01:16.840 --> 01:17.980 to be returned. 01:17.980 --> 01:21.020 So we want the first elements greater than six. 01:21.070 --> 01:29.920 So our function is going to be like this returning value greater than six. 01:30.240 --> 01:33.700 So the first elements which fulfills the condition is seven. 01:33.710 --> 01:36.680 And that's the one that's being returned. 01:37.020 --> 01:47.670 Now if you want to return the index instead of the value you just use find index instead of a find and 01:47.700 --> 01:51.530 that's the index of the first elements for fear in the condition. 01:51.830 --> 01:53.190 So now let's move to the next one. 01:53.190 --> 02:02.340 So we want to find the first element which if added to its index the sum is smaller than five. 02:03.390 --> 02:12.420 So now again we're going to use the find method but this time we are using the index as well in the 02:12.420 --> 02:13.130 condition. 02:13.530 --> 02:22.610 So basically you can pass two elements to your function or two parameters. 02:22.690 --> 02:25.870 The second one is optional and that's the index. 02:25.870 --> 02:33.840 So we want the value plus the index to be greater than or less than five. 02:33.910 --> 02:34.350 All right. 02:34.420 --> 02:38.110 So let's try this and see what we get. 02:38.110 --> 02:44.110 Are you getting any defined and that's because no elements inside the array fulfills this condition. 02:44.140 --> 02:52.130 So if you change five to six then obviously the first element is going to fulfill the condition and 02:52.610 --> 02:54.500 you're gonna get five of the results. 02:55.660 --> 02:56.410 Okay. 02:56.690 --> 03:08.280 So now let's get to the index of ISIS in value so to do this you use index off. 03:08.460 --> 03:11.570 So let's get the index of seven and that's one. 03:12.960 --> 03:21.840 Now you can check if a certain elements exists inside the array by using the includes method like this. 03:21.840 --> 03:27.870 So we try to scan the return true because two is there. 03:27.870 --> 03:35.900 All right so now let's do something new so we're going to copy in position 1 which is 7. 03:36.180 --> 03:40.700 We're going to copy the chunk between 0 and 1. 03:40.770 --> 03:43.060 So that chunk we're gonna copy. 03:43.140 --> 03:48.350 That's chunk in that position all right. 03:49.910 --> 03:55.380 So to do this we gonna use a method called copy within. 03:55.400 --> 04:10.280 So first let's look X to see the current value of x and we're gonna use X dot copy within 2 Copy in 04:10.280 --> 04:13.800 that position this junk. 04:14.580 --> 04:17.910 So we're gonna start with the target no target. 04:17.940 --> 04:19.140 There's gonna be the position. 04:19.140 --> 04:31.050 So in our case one and we want to copy the chunk from the index 0 to index 1 so the starting index is 04:31.110 --> 04:40.470 0 and the loss index is 1 but we're gonna need to use 2 because the last one is not included. 04:41.230 --> 04:44.960 All right so let's log X again. 04:46.930 --> 04:55.270 So now X is 5 5 7 2 because we copied that right there. 04:55.360 --> 04:55.980 All right. 04:56.050 --> 05:01.450 So these two are replaced by 5 and 7. 05:01.850 --> 05:02.300 All right. 05:02.320 --> 05:08.080 So now let's copy in position to the chunk between 1 and the end. 05:08.080 --> 05:17.060 So position 2 is right there and we gonna copy the chunk between 5 and the end. 05:17.230 --> 05:18.140 All right. 05:18.310 --> 05:19.090 So as you do this 05:22.380 --> 05:29.630 the arguments we're gonna pass to copy within are gonna be as following so we copying in position 2. 05:29.650 --> 05:31.690 So that's our position. 05:31.780 --> 05:34.090 So the chunk between 1 and the end. 05:34.210 --> 05:38.530 So if you place one only without 05:41.070 --> 05:45.150 saying what the end is going to be then he's gonna carry on till the end. 05:45.150 --> 05:49.420 So it is log X and see what we get s. 05:49.620 --> 06:01.440 So we copied in position to from 5 all right till the end. 06:01.570 --> 06:08.470 So we're gonna go to position 2 which is that's 1 and we're gonna copy from there to there. 06:08.800 --> 06:15.980 So 7 becomes 5 and 2 becomes 7 and then we reach the end of our array. 06:16.060 --> 06:22.680 So we can't copy 2 right there because we don't have any other places available. 06:22.690 --> 06:23.610 All right. 06:23.950 --> 06:28.340 Now let's try something else so let's copy in position 3. 06:28.540 --> 06:31.030 The first value of the array. 06:31.270 --> 06:40.750 So if you do this you only use the position which is three and this will imply that you are just copying 06:40.770 --> 06:46.180 in position three whatever you quotes as the first elements of the array. 06:46.180 --> 06:50.440 In our case five so log X and see what we get. 06:51.190 --> 06:54.610 And this is what we expected. 06:54.650 --> 06:55.090 All right. 06:55.090 --> 06:58.380 So now let's move to something else. 06:58.390 --> 07:05.280 So we want to fill our array with forms from position 1 to 1. 07:06.730 --> 07:10.270 So to do this we use the fill method. 07:10.330 --> 07:14.470 So it's best if you specify the position of the value. 07:14.560 --> 07:19.420 So we want to use the value for we're going to fill from position 1 to position 1. 07:19.450 --> 07:22.110 So the starting position comes next. 07:22.110 --> 07:24.170 And the end position comes up. 07:24.190 --> 07:27.670 So we're gonna use to here because the last position is not included. 07:27.700 --> 07:32.810 So if you say from 1 to 2 this means from 1 to 2 not included. 07:32.890 --> 07:36.400 So from 1 to 3 means that is gonna be 1 and 2. 07:36.400 --> 07:36.680 All right. 07:36.730 --> 07:38.360 So in our case from 1 to 2. 07:38.370 --> 07:41.470 Meaning that it's only position want to 1. 07:41.470 --> 07:52.410 So if you log X then you're gonna see that we field X with the values 4 from position 1 to position 07:52.410 --> 07:52.580 on. 07:52.930 --> 07:58.190 So if you try 3 The then you gonna get it from position 1 to position 2. 07:58.300 --> 08:01.860 So let's leave it like that for now. 08:02.120 --> 08:07.450 Now the next one we're feeling X with an object from position 2 to the end. 08:07.450 --> 08:12.100 So X fill with this object. 08:12.610 --> 08:12.990 All right. 08:14.740 --> 08:19.120 From position to to the end. 08:19.120 --> 08:23.380 So if you don't specify the end position then it carries on till the end. 08:23.530 --> 08:28.000 So it's log X and see what we get. 08:28.000 --> 08:32.170 So we started from position 2 and we carried on carried on till the end. 08:33.190 --> 08:34.930 So now something interesting. 08:34.960 --> 08:44.590 So what if you check if the values US position to a position three are equal or not. 08:44.680 --> 08:45.640 So is this point that 09:09.850 --> 09:12.190 we are getting true. 09:12.670 --> 09:24.590 Now what if you try this at this time using those object literally like That's and you're getting false. 09:24.700 --> 09:26.430 Interesting. 09:26.500 --> 09:36.300 So the reason why we getting different results is because when you copy this value inside X or the array 09:36.360 --> 09:42.810 X you're actually passing a reference only of an object. 09:43.200 --> 09:49.870 So the same reference is actually being passed to the elements after position two of the elements are 09:49.890 --> 09:51.640 ask position 3. 09:51.690 --> 09:54.090 So here you get true 09:56.610 --> 10:02.580 because you are passing a reference only. 10:02.760 --> 10:16.350 So this is the same as if you would you were creating a variable Y where you saw your objects and then 10:16.350 --> 10:17.190 you were passing 10:19.880 --> 10:26.820 the objects like that you passing a reference to these objects in memory. 10:27.230 --> 10:29.300 It's absolutely the same. 10:29.550 --> 10:35.560 All right so let's keep it all as it was. 10:35.680 --> 10:39.160 Hopefully this makes sense okay. 10:39.460 --> 10:44.950 So this was a quick overview of some new methods of arrays in Essex.