1
00:00:00,570 --> 00:00:06,210
In the previous video, we talked about the structure in this video.

2
00:00:06,210 --> 00:00:09,630
Let's focus on risk parameters.

3
00:00:09,900 --> 00:00:19,530
Risk parameters are a way to pass an arbitrary number of elements to a function, which means that we

4
00:00:19,530 --> 00:00:27,420
can pass an indeterminate element to a function if this particular definition is not clear to you.

5
00:00:27,450 --> 00:00:29,790
Let's demonstrate something here.

6
00:00:30,420 --> 00:00:34,650
Let's say that we have this particular institution.

7
00:00:35,440 --> 00:00:37,210
And this institution.

8
00:00:37,210 --> 00:00:40,420
It takes, let's say, 20 applicants.

9
00:00:41,540 --> 00:00:48,620
So after 20 applicants, this particular school cannot accept any incoming application.

10
00:00:49,010 --> 00:00:54,950
And let's say that we have, let's say, 40 or more students left.

11
00:00:55,400 --> 00:00:55,970
Good.

12
00:00:56,060 --> 00:00:58,190
But with rest parameters.

13
00:00:58,190 --> 00:00:59,840
What is saying is that.

14
00:00:59,840 --> 00:01:00,440
Okay.

15
00:01:00,560 --> 00:01:04,700
Well, we are saying that we are taking 20 applicants.

16
00:01:04,730 --> 00:01:11,030
But any applicant who applies, we will still what accommodates you into the school.

17
00:01:11,540 --> 00:01:18,140
So if we take this in code, we can say that the school is a function.

18
00:01:19,120 --> 00:01:22,540
And then the applicants are called the agreement.

19
00:01:23,740 --> 00:01:28,960
So inside this coup, it hosted all the applicants.

20
00:01:29,080 --> 00:01:33,550
So this applicants are called the agreement.

21
00:01:33,550 --> 00:01:35,890
So with the rest parameter.

22
00:01:36,570 --> 00:01:45,480
We have access to the parameters we are requesting and any additional parameters being passed into the

23
00:01:45,480 --> 00:01:46,110
function.

24
00:01:46,680 --> 00:01:53,190
So let's get back to the slide and let's take this one to as an example, let's say that this is also

25
00:01:53,190 --> 00:01:54,660
a function, right?

26
00:01:54,660 --> 00:02:02,190
So this function, let's say it takes, let's say five or ten users, but after it has finished taking

27
00:02:02,190 --> 00:02:07,290
the required users, we still have some users which has left.

28
00:02:07,410 --> 00:02:14,850
So with rest parameters, we can still pass this user into the function and the function can have access

29
00:02:14,850 --> 00:02:16,500
to the rest users.

30
00:02:16,710 --> 00:02:23,970
So as the name implies rest, it takes the rest of the argument and the method using the red dot.

31
00:02:24,000 --> 00:02:27,540
So let's get back to visual ID code and demonstrate that.

32
00:02:27,540 --> 00:02:33,780
Well, so here let me comment and call this one as risks parameters.

33
00:02:34,020 --> 00:02:40,230
To better understand risk parameters, we need to understand what is called engagement.

34
00:02:40,230 --> 00:02:42,360
So let me demonstrate that one for you to see.

35
00:02:42,630 --> 00:02:46,950
Let's say we have a function that adds two numbers.

36
00:02:48,210 --> 00:02:52,680
To see two numbers, and this one would take in A and B.

37
00:02:53,070 --> 00:02:58,650
So inside this function, I have access to what is called the argument.

38
00:02:59,070 --> 00:03:08,760
So if I call the function the at two numbers and let's see the equipment that we have inside the function.

39
00:03:09,480 --> 00:03:10,470
Let me enlarge it.

40
00:03:10,500 --> 00:03:17,280
If we see that this looks like an array because we have the square bracket here and the close in here

41
00:03:17,280 --> 00:03:18,150
is that.

42
00:03:18,360 --> 00:03:28,410
But it's not an array where the argument object is not a real array while rest parameters are an array.

43
00:03:28,440 --> 00:03:29,640
So I'll show you very soon.

44
00:03:29,640 --> 00:03:33,410
So take note that the argument is not real array.

45
00:03:33,420 --> 00:03:40,460
So anything that we pass to this function will be available inside the argument.

46
00:03:40,470 --> 00:03:41,640
So let's pass in here.

47
00:03:41,640 --> 00:03:42,960
Let's say 20 here.

48
00:03:43,080 --> 00:03:51,390
If I save it, we see that it has added inside my argument and let's say I want at ten we see that it's

49
00:03:51,390 --> 00:03:54,030
been added inside my argument.

50
00:03:54,390 --> 00:04:02,490
Okay, so anything that you pass into the function as an argument would be available inside this argument

51
00:04:02,520 --> 00:04:03,240
property.

52
00:04:03,390 --> 00:04:05,220
That's one thing to bear in mind.

53
00:04:05,550 --> 00:04:14,550
Again, this is not rare array, meaning we cannot use some of the methods on this particular argument.

54
00:04:14,550 --> 00:04:16,800
So now you know what argument is.

55
00:04:16,800 --> 00:04:21,450
It holds all the arguments we pass to this particular function.

56
00:04:21,450 --> 00:04:23,940
Now let's talk about rest.

57
00:04:24,420 --> 00:04:33,450
So now inside this function, how can we make use of res to rest is like an improvement on the argument.

58
00:04:33,480 --> 00:04:39,600
Okay, before I show you the rest, let's try to loop through this particular argument here.

59
00:04:39,750 --> 00:04:47,790
VERRASTRO We can still have some methods, but ideally is not real every so we never use that one by

60
00:04:47,790 --> 00:04:49,620
using some method on that.

61
00:04:49,620 --> 00:04:52,320
That is why rest comes into play.

62
00:04:52,590 --> 00:04:55,260
So let's say let me remove this from here.

63
00:04:55,260 --> 00:05:01,860
And for rest parameters we bring in dot, dot, dot and then any variable we can make it.

64
00:05:01,860 --> 00:05:07,290
So let's say the arguments, the ag or the arguments or rest.

65
00:05:08,300 --> 00:05:09,830
Is that so?

66
00:05:09,830 --> 00:05:11,510
If I console.log.

67
00:05:11,540 --> 00:05:12,320
Rest.

68
00:05:13,050 --> 00:05:16,100
Now you could see that this is perfect array.

69
00:05:16,410 --> 00:05:24,000
So it means that we can have access to any variable that we pass into this function and to pack them

70
00:05:24,000 --> 00:05:27,000
or put them inside an array like that.

71
00:05:27,120 --> 00:05:28,510
That is good, right?

72
00:05:28,530 --> 00:05:36,360
So with this one, I can add as many arguments with this particular function I can pass in, let's say

73
00:05:36,360 --> 00:05:41,010
even me a string and then to be added into the array.

74
00:05:41,430 --> 00:05:42,780
And this is crucial.

75
00:05:42,840 --> 00:05:48,540
Let's say that this particular function takes in two arguments.

76
00:05:48,570 --> 00:05:51,300
Now we have a function with rest parameter.

77
00:05:51,510 --> 00:05:55,800
What about a function with argument and with rest parameter?

78
00:05:55,800 --> 00:05:59,020
Before I would demonstrate to you the logic behind this function.

79
00:05:59,040 --> 00:06:06,240
Let's go ahead and create a function that would take in our own arguments and then rest with rest parameter.

80
00:06:06,720 --> 00:06:11,700
So now let me copy this one and comment this one out and come down here.

81
00:06:11,820 --> 00:06:17,730
Now here we can pass it A and B like that.

82
00:06:17,760 --> 00:06:20,010
Now we know this one holds the.

83
00:06:20,040 --> 00:06:25,410
So here I can have access to my A and then B and I have two and 20.

84
00:06:25,440 --> 00:06:31,500
You can see that it couldn't print out the three and me because according to this implementation, it

85
00:06:31,500 --> 00:06:34,200
says that this function needs two arguments.

86
00:06:34,230 --> 00:06:37,800
So we take in 20 and ten, as we see here.

87
00:06:38,130 --> 00:06:47,010
But to have access to extra argument we pass in, we have access to it by making of comma and dots the

88
00:06:47,010 --> 00:06:47,790
ax.

89
00:06:48,600 --> 00:06:55,830
The argument or risk it can be anything race or the and so most times make use of race or the arguments.

90
00:06:56,130 --> 00:06:58,500
So now I have this.

91
00:06:58,500 --> 00:07:00,960
So if I console.log the rest.

92
00:07:00,990 --> 00:07:01,860
Let's see.

93
00:07:02,310 --> 00:07:04,500
The difference is if I console.log.

94
00:07:04,500 --> 00:07:05,250
The rest.

95
00:07:05,760 --> 00:07:06,720
Now.

96
00:07:07,960 --> 00:07:08,690
It's wrists.

97
00:07:09,100 --> 00:07:11,140
Yes, you can see that.

98
00:07:11,140 --> 00:07:12,970
Now, we have two things happening here.

99
00:07:13,450 --> 00:07:18,730
We have the original agreement, which is 220 and ten as that.

100
00:07:18,820 --> 00:07:26,980
But for the rest, it has taken the rest of agreements and then put them inside an array that is key

101
00:07:26,990 --> 00:07:34,300
nutrient bearing in mind the rest agreements, take the rest of agreements and put them inside an array.

102
00:07:34,450 --> 00:07:40,420
And remember, one function can take in only one rest parameter.

103
00:07:40,780 --> 00:07:42,910
I'm thinking, what about a can I add?

104
00:07:42,910 --> 00:07:44,410
Let's say another rest.

105
00:07:44,590 --> 00:07:46,350
Let's say dot, dot, dot.

106
00:07:46,360 --> 00:07:48,070
Let's say raise to.

107
00:07:49,140 --> 00:07:50,020
Now see that?

108
00:07:50,040 --> 00:07:50,970
Got an arrow.

109
00:07:54,300 --> 00:07:58,020
So a function takes in only one race parameter.

110
00:07:58,050 --> 00:08:04,980
Let's create a simple function that would take in some arguments and find which one is the maximum.

111
00:08:04,980 --> 00:08:09,930
So the function would go like this find max or the maximum.

112
00:08:09,930 --> 00:08:13,830
And this function, let's say I want to find three numbers.

113
00:08:13,830 --> 00:08:21,270
Let's say A, B and C as a C note, three, C as that.

114
00:08:21,540 --> 00:08:23,880
And now I'm going to use map.

115
00:08:24,680 --> 00:08:26,300
Moth dart.

116
00:08:27,600 --> 00:08:28,590
Maximum.

117
00:08:28,620 --> 00:08:37,919
Then I'll pass in A, B and C, so let me console.log this one and let's see, just console.log it.

118
00:08:38,370 --> 00:08:38,880
Okay.

119
00:08:38,880 --> 00:08:43,860
So now if I call the function called find max maximum.

120
00:08:44,010 --> 00:08:48,610
Now pass in, let's say ten, 20 and 30.

121
00:08:48,630 --> 00:08:50,360
Which one is the highest?

122
00:08:50,370 --> 00:08:55,590
So if I save it, I get 30 because 30 is the highest among this.

123
00:08:55,860 --> 00:09:01,000
So what about if I add, let's say 100 into it number?

124
00:09:01,020 --> 00:09:07,230
So I still see 30 because it didn't take this one into consideration.

125
00:09:07,320 --> 00:09:11,370
So to have access to this one, I'm going to use the rest parameter.

126
00:09:11,640 --> 00:09:17,280
Remember, the rest parameter will take the individual record and put it inside an array.

127
00:09:17,610 --> 00:09:21,960
So it is I'm going to be so inside my argument here.

128
00:09:21,960 --> 00:09:25,910
Instead of using some static arguments here, I'm going to use the dots.

129
00:09:25,920 --> 00:09:28,890
Let's see the rest of the numbers.

130
00:09:29,310 --> 00:09:37,410
And inside here, I'm going to use the same syntax as dot, dot, dot risk, meaning I'm taking the

131
00:09:37,410 --> 00:09:44,180
argument from here and passing to this particular method or function if I save it by list.

132
00:09:44,220 --> 00:09:46,920
Now see that I get 102.

133
00:09:47,890 --> 00:09:48,580
So let's see.

134
00:09:48,580 --> 00:09:54,460
I want to add let's say 200 and let's see, I could see that now we have it as 200 because now because

135
00:09:54,460 --> 00:10:01,100
of risk, it is taking all the agreement you pass in and then pass into this maximum function.

136
00:10:01,120 --> 00:10:04,000
That is how race works.

