1
00:00:00,320 --> 00:00:07,290
You might get a question like this right to function, which helps to achieve multiply A and B and returns

2
00:00:07,290 --> 00:00:13,860
product of A and B, and as you can see here, we have this strange notation multiply then A and B not

3
00:00:13,860 --> 00:00:19,260
like two arguments, but this is the first call of the function and this is a second call of the function.

4
00:00:22,530 --> 00:00:27,630
And actually, if you are getting such question, it means that you are going in the direction of Karen

5
00:00:27,810 --> 00:00:31,950
and Karen is a special possibility in JavaScript to carry a function.

6
00:00:32,070 --> 00:00:33,900
And then we can call it like this.

7
00:00:34,380 --> 00:00:38,280
And actually, here we can implement this stuff with super basic current.

8
00:00:38,520 --> 00:00:39,810
Let's try this out now.

9
00:00:40,080 --> 00:00:42,960
So what I want to do, I want to create multiply function.

10
00:00:43,140 --> 00:00:44,880
And here we're get in our way.

11
00:00:44,890 --> 00:00:47,010
So it will be number one, for example.

12
00:00:47,220 --> 00:00:52,500
And here we want to return a function because as you can see here on the top, we're calling on the

13
00:00:52,500 --> 00:00:57,690
result of monkey to play a b, which means our multiply master return function.

14
00:00:57,720 --> 00:01:03,180
So here we can write that we are getting F function, which will get B, this is number two, for example.

15
00:01:03,390 --> 00:01:08,250
And here inside we want to multiply our number one and number two.

16
00:01:08,460 --> 00:01:14,280
In this case, our second function will deliver fast multiplication of number one and number two.

17
00:01:14,520 --> 00:01:16,010
And this is how we can use it.

18
00:01:16,020 --> 00:01:17,610
We can write here console.log.

19
00:01:17,910 --> 00:01:22,710
We want to call here our multiply function and we are passing a, for example, two.

20
00:01:22,890 --> 00:01:27,600
And after this were Column B, this is our second function and we're passing inside three.

21
00:01:27,870 --> 00:01:33,420
Let's look and Rosa am reloading the page and we're getting six, which means this code is working.

22
00:01:33,570 --> 00:01:36,900
And actually, you can write this multiply function in better way.

23
00:01:37,050 --> 00:01:41,510
You can simply mid-year returns and then it will be a simple single line.

24
00:01:41,820 --> 00:01:45,300
So we have here multiply function and we get to number one here.

25
00:01:45,580 --> 00:01:51,570
Then we want to return a function and we're getting here number two, and we want to multiply our number

26
00:01:51,570 --> 00:01:53,340
one, multiply number two.

27
00:01:53,610 --> 00:01:57,660
And this is exactly this same logic, but it is written in the single line.

28
00:01:57,960 --> 00:02:00,180
I will now command told the previous code.

29
00:02:00,180 --> 00:02:06,030
And let's check, as you can see, where getting exactly the same result, but this is not really current.

30
00:02:06,420 --> 00:02:11,250
So if you solve such tasks, typically you will be asked, OK, but what did you write here?

31
00:02:11,430 --> 00:02:12,410
What does this mean?

32
00:02:12,420 --> 00:02:14,370
Why we need such strange notation?

33
00:02:14,670 --> 00:02:20,100
And actually, you must tell that token here regarding current is the next question that you might get

34
00:02:20,100 --> 00:02:24,270
is create a card of function, and this is actually a difficult question.

35
00:02:24,390 --> 00:02:29,520
And if you didn't have any experience of current functions, then probably you won't answer it.

36
00:02:32,740 --> 00:02:38,500
This is why here we a look how we can create the kind of function and why do we need them and actually

37
00:02:38,500 --> 00:02:43,900
carry functions working exactly like home, multiply here so we can write in browser, for example,

38
00:02:43,900 --> 00:02:44,440
Kyrie.

39
00:02:44,590 --> 00:02:45,760
And this is our function.

40
00:02:45,940 --> 00:02:49,060
We must always pass inside the function that we want to carry.

41
00:02:49,360 --> 00:02:53,470
In this case, we have, for example, a function with A, B and C.

42
00:02:53,480 --> 00:02:59,070
So we have three arguments and we want to just some a plus B plus c.

43
00:02:59,380 --> 00:03:05,440
The main point is that the result of Kyrie is a function, and let's name it carried some.

44
00:03:05,770 --> 00:03:07,760
So this is how we're using Kyrie.

45
00:03:07,780 --> 00:03:09,190
What we can do with courage.

46
00:03:09,190 --> 00:03:14,450
Some later we can weekends right here, our arguments, we have three arguments how we want.

47
00:03:14,890 --> 00:03:17,260
For example, we can right here one two three.

48
00:03:17,440 --> 00:03:23,350
Just like three normal arguments, we can also call it was one, two and three, which means we are

49
00:03:23,350 --> 00:03:26,800
not getting a result until we get getting through arguments.

50
00:03:27,070 --> 00:03:33,220
So, for example, we have only one argument here one then it will return the partially applied function,

51
00:03:33,430 --> 00:03:35,350
which means we're getting back a function.

52
00:03:35,530 --> 00:03:40,960
And then if we will call that function and pass two arguments, then we're getting enough arguments

53
00:03:41,080 --> 00:03:42,670
and we will return the result.

54
00:03:42,910 --> 00:03:46,390
And of course, it should be also possible to call the function like this.

55
00:03:46,660 --> 00:03:49,840
So first of all, Colin, it was one and then were Colin.

56
00:03:49,840 --> 00:03:50,980
It was two and three.

57
00:03:51,310 --> 00:03:56,230
And this is how normal the current function is working and we've all created just now.

58
00:03:56,590 --> 00:03:59,920
So what we want to do here, we want to create the correct function.

59
00:04:00,130 --> 00:04:05,800
And as I said, this is more advanced stuff and actually it is a good idea to try this function with

60
00:04:05,800 --> 00:04:06,700
ActionScript five.

61
00:04:06,730 --> 00:04:12,220
So was function key words just because we were writing something which will be used as a library?

62
00:04:12,580 --> 00:04:13,300
This is way here.

63
00:04:13,300 --> 00:04:14,710
I want to write a function.

64
00:04:14,920 --> 00:04:20,860
And here we are getting the function and actually here on the top, let's write our usage so we understand

65
00:04:20,860 --> 00:04:22,000
what we are talking about.

66
00:04:22,210 --> 00:04:27,300
So we said here that we want our car, read some and were Colin here.

67
00:04:27,310 --> 00:04:34,330
Our carry function and inside were passing the function with A, B and C, and here we want to sum a

68
00:04:34,360 --> 00:04:35,260
b and C.

69
00:04:35,560 --> 00:04:39,400
And actually, I can even write it here on the bottom after our car.

70
00:04:39,700 --> 00:04:41,500
So we can test if it's working.

71
00:04:41,740 --> 00:04:46,810
So actually, as you can see, here is our carry function and we're getting inside the function.

72
00:04:46,840 --> 00:04:48,130
This is our f.n.

73
00:04:48,370 --> 00:04:52,810
So this ABC and A-plus B-plus here is our function here.

74
00:04:52,960 --> 00:04:56,650
What we want to do now, we want to know how many arguments we have here.

75
00:04:56,980 --> 00:04:57,700
This is way here.

76
00:04:57,700 --> 00:05:00,520
I want to create a property which is called Arati.

77
00:05:00,880 --> 00:05:05,800
And here we can just write function length and we will get them on the arguments here.

78
00:05:05,830 --> 00:05:06,730
Let's check this out.

79
00:05:06,730 --> 00:05:08,170
Console.log, Verity.

80
00:05:08,350 --> 00:05:09,820
And here is our editor.

81
00:05:10,120 --> 00:05:16,130
I'm looking in the browser and we're getting three because here we have three arguments A, B and C.

82
00:05:16,540 --> 00:05:22,420
Now we want to return here a function because we know that current function is always a function.

83
00:05:22,690 --> 00:05:24,490
This is why here let's write function.

84
00:05:24,490 --> 00:05:25,120
Let's name it.

85
00:05:25,120 --> 00:05:26,290
For example, f one.

86
00:05:26,560 --> 00:05:31,230
And here I want to spread our arguments and let's check what we have inside.

87
00:05:31,240 --> 00:05:34,930
So here console.log F1 and here are our arguments.

88
00:05:35,230 --> 00:05:37,000
And actually when lot the page.

89
00:05:37,000 --> 00:05:41,260
As you can see, we don't get anything because we didn't call this card some.

90
00:05:41,500 --> 00:05:48,220
So what we must do afterwards, we must call this some as a function and we can pass inside something.

91
00:05:48,400 --> 00:05:50,470
In our case, we can pass two or three.

92
00:05:50,770 --> 00:05:52,300
This are our three parameters.

93
00:05:52,570 --> 00:05:56,230
I'm reloading the page and we're getting here f one one two three.

94
00:05:56,410 --> 00:05:59,100
So we're getting all arguments as an array.

95
00:05:59,110 --> 00:06:04,000
This is our idea, and obviously we can also call this function just was one.

96
00:06:04,150 --> 00:06:06,610
Then we will get array was just one argument.

97
00:06:07,030 --> 00:06:13,120
So what I want to do inside, I want to check how many arguments we've got or if we got enough arguments

98
00:06:13,120 --> 00:06:13,600
or not.

99
00:06:13,900 --> 00:06:14,660
This is way here.

100
00:06:14,680 --> 00:06:18,190
Inside return, we can compare OK, arguments, length.

101
00:06:18,460 --> 00:06:22,120
This is the length of our array is bigger or equal everything.

102
00:06:22,360 --> 00:06:26,500
And this means that we are getting enough arguments to come out of the function.

103
00:06:26,500 --> 00:06:30,310
So here I want to console.log enough arguments.

104
00:06:30,580 --> 00:06:35,890
In this case, I just want to return here our function and call it with our arguments.

105
00:06:35,890 --> 00:06:42,400
So I'm spreading our arguments again, and it will just put here all arguments just like they were previously.

106
00:06:42,640 --> 00:06:46,960
Let's check the SA time to load in the page and we've got a message enough arguments.

107
00:06:47,050 --> 00:06:50,080
And actually, here we can console.log what we are getting back.

108
00:06:50,320 --> 00:06:52,550
In this case, we must get our result.

109
00:06:52,600 --> 00:06:58,600
I'm relied in the page where get in six it is working correctly, which actually means our code already

110
00:06:58,600 --> 00:07:01,660
works when we are passing inside three arguments at once.

111
00:07:01,990 --> 00:07:04,720
But it won't work when we are passing less than that.

112
00:07:04,990 --> 00:07:11,290
This is why we must write here L's condition and inside we can write, for example, console.log need

113
00:07:11,440 --> 00:07:12,670
more arguments.

114
00:07:13,000 --> 00:07:15,640
And now after this, we want to return a function.

115
00:07:15,640 --> 00:07:21,940
As I already said, if we're past, for example, encourage just one argument, it must return a function

116
00:07:22,090 --> 00:07:24,370
where we can pass additional arguments.

117
00:07:24,700 --> 00:07:30,910
This is why here we must return a function and we can name it, for example, F2 and inside we will

118
00:07:30,910 --> 00:07:31,570
pass more.

119
00:07:31,910 --> 00:07:36,230
Arguments, which actually means this is our first call, this is our second call.

120
00:07:36,500 --> 00:07:41,060
For example, here one carried some this is also a correct function.

121
00:07:41,270 --> 00:07:47,210
So let's name it partially correct some and have a call, correct some.

122
00:07:47,420 --> 00:07:48,970
Now here I want to cancel.

123
00:07:48,980 --> 00:07:52,160
OK, partially correct some so we can check what it does.

124
00:07:52,520 --> 00:07:54,980
As you can see here, we inside need arguments.

125
00:07:55,130 --> 00:07:57,740
And here is our function with more arguments.

126
00:07:57,950 --> 00:08:00,980
And actually here we want to pass and set some arguments.

127
00:08:01,220 --> 00:08:05,090
For example, we can pass here two and three, and it will be exactly this.

128
00:08:05,090 --> 00:08:07,340
More arguments that were rolled here.

129
00:08:07,670 --> 00:08:14,360
What we want to do now, we want to concatenate our arguments with my arguments to put all our arguments

130
00:08:14,360 --> 00:08:16,070
inside the color of the function.

131
00:08:16,370 --> 00:08:22,370
This is where here we can create a variable in your arguments and we want to concatenate our arguments.

132
00:08:22,610 --> 00:08:27,080
And I am calling second cut and then passing inside more arguments.

133
00:08:27,290 --> 00:08:34,130
Now here we don't need to call our fan function just like we did here, but we must call our F1 function

134
00:08:34,310 --> 00:08:39,980
because we want this check for enough arguments again and again, which means we are calling it recursively.

135
00:08:40,220 --> 00:08:45,710
This is why here I want to return F1 function and I want to spread all our new arguments.

136
00:08:45,920 --> 00:08:48,680
This is why here three thoughts and your arguments.

137
00:08:48,980 --> 00:08:54,570
Let's check the real time to load in the page here, where I get in arguments and enough arguments.

138
00:08:54,590 --> 00:08:56,270
What does it have a mean here?

139
00:08:56,270 --> 00:09:01,010
Does our current some robust hear one argument we're getting in this house?

140
00:09:01,040 --> 00:09:02,240
This is our console.log.

141
00:09:02,240 --> 00:09:03,230
Need more arguments?

142
00:09:03,470 --> 00:09:05,510
And here's our additional function.

143
00:09:05,870 --> 00:09:10,270
This is where we're calling this function, and we're passing here our arguments.

144
00:09:10,310 --> 00:09:11,690
This is this variable.

145
00:09:12,050 --> 00:09:14,360
Now here we're concatenated our one.

146
00:09:14,510 --> 00:09:15,800
This is what we passed here.

147
00:09:15,950 --> 00:09:18,560
And two three and we called our F1.

148
00:09:18,740 --> 00:09:20,310
So we're getting here again.

149
00:09:20,330 --> 00:09:24,890
We have enough arguments and Kiev calling our function, and we're getting six.

150
00:09:24,920 --> 00:09:28,410
Now let's remove all our consulates logs and check how it's working.

151
00:09:28,430 --> 00:09:30,650
So what I want to try here is our card.

152
00:09:30,650 --> 00:09:35,120
Some how we can call it, we can call it was one, two and three and we're getting six.

153
00:09:35,120 --> 00:09:36,350
It is working now.

154
00:09:36,350 --> 00:09:37,640
We can call it was one.

155
00:09:37,820 --> 00:09:42,440
As you can see, we're getting back a function and we now can call it with two and three.

156
00:09:42,650 --> 00:09:47,990
As you can see, we're getting six also, which means it is working and now we can call it here, restore.

157
00:09:47,990 --> 00:09:53,270
And after this with three and we're getting six, which actually means it is working correctly with

158
00:09:53,270 --> 00:09:58,460
any amount of arguments and the have recovered some function where we have ten arguments.

159
00:09:58,640 --> 00:10:01,370
And then here we're doing some operation with stand arguments.

160
00:10:01,640 --> 00:10:07,340
Then here we will call this function recursively until we get all needed arguments, as you can see

161
00:10:07,340 --> 00:10:09,710
right and carry function is not that easy.

162
00:10:09,830 --> 00:10:15,380
And if you never did it before, it is difficult to write this directly in the interview, especially

163
00:10:15,380 --> 00:10:19,250
just on the piece of paper and the last question that you might get here.

164
00:10:19,250 --> 00:10:23,750
Okay, but why do we need carry function and what your correct function can do?

165
00:10:27,030 --> 00:10:33,140
This is why he he'll want now to use our country function on our rail project and what we can do here,

166
00:10:33,150 --> 00:10:36,520
we can carry two functions get and map.

167
00:10:36,540 --> 00:10:37,590
Let's try this out.

168
00:10:37,740 --> 00:10:40,830
I want to create a get function and they want to carry it.

169
00:10:41,100 --> 00:10:46,260
This is why I am calling this car function and inside am passing the function with two properties.

170
00:10:46,530 --> 00:10:48,150
First of all, it will be property.

171
00:10:48,420 --> 00:10:50,370
And secondly, it will be an object.

172
00:10:50,400 --> 00:10:51,940
And what we want to return here.

173
00:10:52,080 --> 00:10:56,190
We just want to take an object by a key and it will be property.

174
00:10:56,490 --> 00:10:57,780
Let's check how it works.

175
00:10:58,050 --> 00:10:59,820
As you can see here, we have our get.

176
00:11:00,030 --> 00:11:01,820
And here we are passing to arguments.

177
00:11:01,830 --> 00:11:03,420
First of all, property, for example.

178
00:11:04,110 --> 00:11:06,930
And secondly, our object, for example, +1.

179
00:11:07,140 --> 00:11:09,090
In this case, we getting one back.

180
00:11:09,360 --> 00:11:12,150
What we can do here, we can now because it's carried.

181
00:11:12,390 --> 00:11:14,280
Just call it was one argument.

182
00:11:14,280 --> 00:11:14,960
Just proceed.

183
00:11:15,510 --> 00:11:18,100
And as you can see, we getting back a current function.

184
00:11:18,120 --> 00:11:20,400
Now we can store it somewhere and reuse.

185
00:11:20,670 --> 00:11:23,340
For example, we can create here additional function.

186
00:11:23,350 --> 00:11:24,120
Get it.

187
00:11:24,570 --> 00:11:27,600
And we're calling here, get with just property ID.

188
00:11:28,260 --> 00:11:33,510
And now, as you can see in browser, we can use get a D function everywhere across our application

189
00:11:33,630 --> 00:11:36,330
on any object to get a property ID from it.

190
00:11:36,480 --> 00:11:39,720
Now we can do exactly the same with map, for example, here.

191
00:11:39,750 --> 00:11:43,320
I want to create map and they want to carry a map function.

192
00:11:43,500 --> 00:11:48,410
So here we're getting a function, which is an argument of the map and values, which is in the.

193
00:11:49,050 --> 00:11:55,170
And here I want just to call a plain JavaScript values that map and then pass in our function inside.

194
00:11:55,440 --> 00:12:00,030
But now our map is carried, which means we can use it everywhere, like a road map.

195
00:12:00,360 --> 00:12:03,300
For example, we can pass inside our map get ID.

196
00:12:03,720 --> 00:12:08,120
And now here is a second argument we can pass an array and just have here.

197
00:12:08,130 --> 00:12:09,450
ID equals one.

198
00:12:09,720 --> 00:12:15,270
As you can see here, with those actually got an array of IDs with the help of the map and actually

199
00:12:15,270 --> 00:12:18,270
help us to arguments, but we can also carry it.

200
00:12:18,270 --> 00:12:22,380
For example, we can name a function here const get IDs.

201
00:12:22,620 --> 00:12:25,320
And here we want to call our map on Get ID.

202
00:12:25,770 --> 00:12:31,830
In this case, we have a partial applied function, get ideas and we can use it to get ideas from any

203
00:12:31,830 --> 00:12:32,310
array.

204
00:12:32,550 --> 00:12:38,610
For example, here where I write and get IDs and where Colin disfunction on the array was object inside

205
00:12:38,610 --> 00:12:40,140
and we have here a D1.

206
00:12:40,320 --> 00:12:45,990
And as you can see, it is working and this is exactly the need of the current to write JavaScript and

207
00:12:45,990 --> 00:12:46,920
functional way.

208
00:12:47,190 --> 00:12:49,230
And yet this is quite advanced topic.

209
00:12:49,470 --> 00:12:54,510
This is why it is completely fine if you don't know this topic as a beginner, but at least you must

210
00:12:54,510 --> 00:12:58,740
have some basic understanding of what is current and why do you need to tone?
