WEBVTT

00:01.470 --> 00:07.250
Before we actually start to describe the main concepts of the version, I would like to introduce you

00:07.250 --> 00:12.960
to some of the very popular and helpful built in JavaScript array methods which allow us to get the

00:12.960 --> 00:15.600
wanted results using writing less code.

00:16.620 --> 00:23.640
Generally, one of the main purposes of updating JavaScript from S5 to S6 was to minimize the amount

00:23.640 --> 00:24.690
of code that you write.

00:25.470 --> 00:30.100
That's why I'm going to describe our helper methods, by the way.

00:30.120 --> 00:35.340
The main goal to use METION methods is to replace for loop whenever it's possible.

00:36.120 --> 00:41.060
One of these methods you are already familiar with because we have used it several times previously.

00:41.340 --> 00:43.320
I'm talking about a right for each method.

00:43.860 --> 00:45.680
If you don't remember, it's well done.

00:45.690 --> 00:46.380
Do not worry.

00:46.380 --> 00:47.520
It happens usually.

00:47.520 --> 00:50.600
And because of that we will recall how it actually works.

00:51.390 --> 01:00.180
Besides the forge method, I'm going to describe map, filter, find every sub and reduce.

01:01.350 --> 01:07.170
Each of these helpers will be discussed and compared to follow up, in order to see clearly the difference,

01:07.440 --> 01:09.630
advantages and disadvantages between them.

01:10.170 --> 01:12.620
All right, let's go to our code editor.

01:13.020 --> 01:16.350
As we said, I'm going to remind you how far each method works for that.

01:16.350 --> 01:19.560
I'm going to create an array names.

01:20.880 --> 01:23.640
Let's insert here some names, Alex.

01:24.900 --> 01:30.720
Then Mary, Niek and Jayne.

01:33.000 --> 01:39.410
At first, in order to iterate through the items and get the names separately, let's use follow right

01:39.420 --> 01:48.030
for then verbal I equals zero, then the condition is less than the length of names.

01:49.710 --> 01:54.720
And then I plus plus let's run running council.

01:57.080 --> 01:58.460
The name is.

02:00.500 --> 02:02.360
And plus, your names, I.

02:05.360 --> 02:08.930
Reload and of course, we have names, as we expected.

02:09.470 --> 02:16.850
OK, we didn't get the same result using forage at first, let's make here a little border for better

02:16.850 --> 02:17.540
readability.

02:18.970 --> 02:24.610
And now let's use Fourche method rights names that forage.

02:26.720 --> 02:32.750
As you remember, we need to pass your function, which will be actually an iterator function and forage

02:32.750 --> 02:37.100
eRate item, this function will be executed as a parameter.

02:37.100 --> 02:39.080
We need to pass your current item.

02:39.600 --> 02:43.000
There is a special convention for our helpers and JavaScript.

02:43.430 --> 02:49.400
I mean that, for example, when we use our name in plural form, that the current item, which is passed

02:49.400 --> 02:52.230
as a parameter, is used in singular form.

02:52.970 --> 02:57.590
So right name here and then gets result in council.

02:59.200 --> 02:59.700
Right.

03:00.640 --> 03:01.570
The name is.

03:03.230 --> 03:06.050
And plus, the current item name.

03:08.460 --> 03:08.890
Result.

03:09.600 --> 03:12.690
And he said that we had the exact same result in council.

03:13.770 --> 03:19.260
All right, before we actually compare Falu and Farish to each other, I'm going to show you how this

03:19.260 --> 03:20.710
method works behind the scenes.

03:22.770 --> 03:29.160
So here we have our array with its containing name items and also the function which is passed in for

03:29.160 --> 03:34.860
each method and has the parameter name as a current item as it's in case.

03:34.920 --> 03:38.180
Follow up, for example, has the iteration feature as well.

03:38.700 --> 03:44.790
So it takes into account the number of items in array and executes this function for each of these items.

03:46.290 --> 03:52.830
If you think about it, you will find that the name of this helper method for each device itself, the

03:52.830 --> 03:53.670
feature it has.

03:54.710 --> 04:02.960
OK, so code is run, function is executed for the first item, Alex, and we get in Castle, the name

04:02.960 --> 04:03.650
is Alex.

04:04.840 --> 04:07.450
And then it runs for second item, Mary.

04:08.680 --> 04:16.170
And we have the name is Mary, and then the same happens for Nick and for Jane as well.

04:17.880 --> 04:24.210
Then because of that, we do not have any more items in the forage terminates execution of this function.

04:25.810 --> 04:26.440
Makes sense.

04:27.910 --> 04:34.630
All right, so you see, we got the same results in both cases, but when we use force method, it's

04:34.630 --> 04:35.590
kind of short way.

04:36.130 --> 04:42.240
We type less and if you type less, it means that there is a lower chance to get errors in bugs.

04:42.890 --> 04:48.430
The logic is much more simple than it is in case of volume because you do not need to define all of

04:48.430 --> 04:49.510
those conditions.

04:50.290 --> 04:55.350
This is an advantage because when you look at some codes, it's easier to understand what's going on.

04:55.630 --> 04:59.050
So it's better to use forage instead of a loop in some cases.

04:59.530 --> 05:04.530
But an advantage for for a loop is that it works faster than the other array hoppers.

05:05.770 --> 05:06.240
All right.

05:06.730 --> 05:12.520
Again, I recommend to test this method and also other methods that will be discussed on your own,

05:12.520 --> 05:17.950
because those helpers or some kind of similar methods and it's easy to be confused if you do not practice

05:17.950 --> 05:18.280
a lot.

05:19.250 --> 05:20.820
OK, let's move on.
