WEBVTT 00:05.590 --> 00:08.660 In this video you're gonna go through a Greek challenge. 00:08.890 --> 00:17.440 Basically you would need to create an empty array and then using a for loop insert three functions logging 00:17.440 --> 00:24.190 their corresponding index inside the array meaning that the function at the index has index 0 is going 00:24.190 --> 00:28.370 to Log 0 the function that's index 1 is gonna log 1 and so on. 00:28.420 --> 00:33.970 So you would need to provide the solution in both yes 5 and yes 6. 00:34.030 --> 00:38.450 So I suggest starting with E6 because that's the easiest one and then moving to yes. 00:38.540 --> 00:39.190 Yes 5. 00:39.190 --> 00:43.240 Just make sure that you master closures in S5 as well. 00:43.240 --> 00:50.170 So I suggest pausing the video here and then coming back once you're done so hopefully you manage to 00:50.170 --> 00:55.180 find the solution so let's create a variable 00:58.140 --> 00:58.870 cause. 00:58.920 --> 01:05.680 For example that's our empty array and then we can have a for loop. 01:06.010 --> 01:10.410 I'm using less here for the E6 syntax 01:13.380 --> 01:23.230 than the condition is I less than three and we increments I my one every time so we're gonna store inside 01:25.340 --> 01:29.090 our array so we can assess the elements of the index. 01:29.150 --> 01:35.180 I to a function of function looks I like that's 01:40.930 --> 01:43.870 so let's check if this works. 01:43.870 --> 01:55.490 So we're gonna call the function which is ugly an index 0 and then the 1 as index 1 then index 2 and 01:55.490 --> 01:58.820 every time we get the right results. 01:59.000 --> 02:10.880 So we know that this is gonna work because every iteration of I will create a new lexical scope and 02:10.880 --> 02:12.520 we get the right value. 02:12.560 --> 02:23.630 I stored every time knowing E6 it was a little bit more challenging because we had to use closures so 02:26.250 --> 02:31.570 let's create another variable costs to 02:35.050 --> 02:38.580 let's call it bike's this time 02:42.870 --> 02:57.620 for loop is going to be done using var so we initialize I 0 and then the remainder is the same 03:04.400 --> 03:10.210 and then we set each elements index I to a function. 03:10.240 --> 03:16.850 So now we know that this is not going to work because in iOS 5 we will keep in memory only one volume. 03:16.870 --> 03:19.990 I am just the last one which is three. 03:20.080 --> 03:21.530 So we need to use closures. 03:21.700 --> 03:29.620 So we're going to have to create a function write that then instead of 03:34.270 --> 03:40.650 setting the value of our elements to a function expression we're going to call a function. 03:40.650 --> 03:41.230 All right. 03:41.320 --> 03:42.820 So that function is going to be 03:48.490 --> 03:52.260 declared like this returning a closure 03:58.860 --> 04:01.110 like this right. 04:01.110 --> 04:07.910 So now let's call bikes 0 04:11.290 --> 04:13.850 by x 1 and bikes to 04:16.920 --> 04:19.060 So thing is being missed the 04:35.120 --> 04:39.610 OK and we guessing the correct values every time. 04:39.610 --> 04:43.880 And that's working thanks to closures. 04:43.890 --> 04:44.760 And here's why. 04:45.630 --> 04:49.440 Well you can see that using a six with less is a lot easier.