You might get a question like this right to function, which helps to achieve multiply A and B and returns
product of A and B, and as you can see here, we have this strange notation multiply then A and B not
like two arguments, but this is the first call of the function and this is a second call of the function.
And actually, if you are getting such question, it means that you are going in the direction of Karen
and Karen is a special possibility in JavaScript to carry a function.
And then we can call it like this.
And actually, here we can implement this stuff with super basic current.
Let's try this out now.
So what I want to do, I want to create multiply function.
And here we're get in our way.
So it will be number one, for example.
And here we want to return a function because as you can see here on the top, we're calling on the
result of monkey to play a b, which means our multiply master return function.
So here we can write that we are getting F function, which will get B, this is number two, for example.
And here inside we want to multiply our number one and number two.
In this case, our second function will deliver fast multiplication of number one and number two.
And this is how we can use it.
We can write here console.log.
We want to call here our multiply function and we are passing a, for example, two.
And after this were Column B, this is our second function and we're passing inside three.
Let's look and Rosa am reloading the page and we're getting six, which means this code is working.
And actually, you can write this multiply function in better way.
You can simply mid-year returns and then it will be a simple single line.
So we have here multiply function and we get to number one here.
Then we want to return a function and we're getting here number two, and we want to multiply our number
one, multiply number two.
And this is exactly this same logic, but it is written in the single line.
I will now command told the previous code.
And let's check, as you can see, where getting exactly the same result, but this is not really current.
So if you solve such tasks, typically you will be asked, OK, but what did you write here?
What does this mean?
Why we need such strange notation?
And actually, you must tell that token here regarding current is the next question that you might get
is create a card of function, and this is actually a difficult question.
And if you didn't have any experience of current functions, then probably you won't answer it.
This is why here we a look how we can create the kind of function and why do we need them and actually
carry functions working exactly like home, multiply here so we can write in browser, for example,
Kyrie.
And this is our function.
We must always pass inside the function that we want to carry.
In this case, we have, for example, a function with A, B and C.
So we have three arguments and we want to just some a plus B plus c.
The main point is that the result of Kyrie is a function, and let's name it carried some.
So this is how we're using Kyrie.
What we can do with courage.
Some later we can weekends right here, our arguments, we have three arguments how we want.
For example, we can right here one two three.
Just like three normal arguments, we can also call it was one, two and three, which means we are
not getting a result until we get getting through arguments.
So, for example, we have only one argument here one then it will return the partially applied function,
which means we're getting back a function.
And then if we will call that function and pass two arguments, then we're getting enough arguments
and we will return the result.
And of course, it should be also possible to call the function like this.
So first of all, Colin, it was one and then were Colin.
It was two and three.
And this is how normal the current function is working and we've all created just now.
So what we want to do here, we want to create the correct function.
And as I said, this is more advanced stuff and actually it is a good idea to try this function with
ActionScript five.
So was function key words just because we were writing something which will be used as a library?
This is way here.
I want to write a function.
And here we are getting the function and actually here on the top, let's write our usage so we understand
what we are talking about.
So we said here that we want our car, read some and were Colin here.
Our carry function and inside were passing the function with A, B and C, and here we want to sum a
b and C.
And actually, I can even write it here on the bottom after our car.
So we can test if it's working.
So actually, as you can see, here is our carry function and we're getting inside the function.
This is our f.n.
So this ABC and A-plus B-plus here is our function here.
What we want to do now, we want to know how many arguments we have here.
This is way here.
I want to create a property which is called Arati.
And here we can just write function length and we will get them on the arguments here.
Let's check this out.
Console.log, Verity.
And here is our editor.
I'm looking in the browser and we're getting three because here we have three arguments A, B and C.
Now we want to return here a function because we know that current function is always a function.
This is why here let's write function.
Let's name it.
For example, f one.
And here I want to spread our arguments and let's check what we have inside.
So here console.log F1 and here are our arguments.
And actually when lot the page.
As you can see, we don't get anything because we didn't call this card some.
So what we must do afterwards, we must call this some as a function and we can pass inside something.
In our case, we can pass two or three.
This are our three parameters.
I'm reloading the page and we're getting here f one one two three.
So we're getting all arguments as an array.
This is our idea, and obviously we can also call this function just was one.
Then we will get array was just one argument.
So what I want to do inside, I want to check how many arguments we've got or if we got enough arguments
or not.
This is way here.
Inside return, we can compare OK, arguments, length.
This is the length of our array is bigger or equal everything.
And this means that we are getting enough arguments to come out of the function.
So here I want to console.log enough arguments.
In this case, I just want to return here our function and call it with our arguments.
So I'm spreading our arguments again, and it will just put here all arguments just like they were previously.
Let's check the SA time to load in the page and we've got a message enough arguments.
And actually, here we can console.log what we are getting back.
In this case, we must get our result.
I'm relied in the page where get in six it is working correctly, which actually means our code already
works when we are passing inside three arguments at once.
But it won't work when we are passing less than that.
This is why we must write here L's condition and inside we can write, for example, console.log need
more arguments.
And now after this, we want to return a function.
As I already said, if we're past, for example, encourage just one argument, it must return a function
where we can pass additional arguments.
This is why here we must return a function and we can name it, for example, F2 and inside we will
pass more.
Arguments, which actually means this is our first call, this is our second call.
For example, here one carried some this is also a correct function.
So let's name it partially correct some and have a call, correct some.
Now here I want to cancel.
OK, partially correct some so we can check what it does.
As you can see here, we inside need arguments.
And here is our function with more arguments.
And actually here we want to pass and set some arguments.
For example, we can pass here two and three, and it will be exactly this.
More arguments that were rolled here.
What we want to do now, we want to concatenate our arguments with my arguments to put all our arguments
inside the color of the function.
This is where here we can create a variable in your arguments and we want to concatenate our arguments.
And I am calling second cut and then passing inside more arguments.
Now here we don't need to call our fan function just like we did here, but we must call our F1 function
because we want this check for enough arguments again and again, which means we are calling it recursively.
This is why here I want to return F1 function and I want to spread all our new arguments.
This is why here three thoughts and your arguments.
Let's check the real time to load in the page here, where I get in arguments and enough arguments.
What does it have a mean here?
Does our current some robust hear one argument we're getting in this house?
This is our console.log.
Need more arguments?
And here's our additional function.
This is where we're calling this function, and we're passing here our arguments.
This is this variable.
Now here we're concatenated our one.
This is what we passed here.
And two three and we called our F1.
So we're getting here again.
We have enough arguments and Kiev calling our function, and we're getting six.
Now let's remove all our consulates logs and check how it's working.
So what I want to try here is our card.
Some how we can call it, we can call it was one, two and three and we're getting six.
It is working now.
We can call it was one.
As you can see, we're getting back a function and we now can call it with two and three.
As you can see, we're getting six also, which means it is working and now we can call it here, restore.
And after this with three and we're getting six, which actually means it is working correctly with
any amount of arguments and the have recovered some function where we have ten arguments.
And then here we're doing some operation with stand arguments.
Then here we will call this function recursively until we get all needed arguments, as you can see
right and carry function is not that easy.
And if you never did it before, it is difficult to write this directly in the interview, especially
just on the piece of paper and the last question that you might get here.
Okay, but why do we need carry function and what your correct function can do?
This is why he he'll want now to use our country function on our rail project and what we can do here,
we can carry two functions get and map.
Let's try this out.
I want to create a get function and they want to carry it.
This is why I am calling this car function and inside am passing the function with two properties.
First of all, it will be property.
And secondly, it will be an object.
And what we want to return here.
We just want to take an object by a key and it will be property.
Let's check how it works.
As you can see here, we have our get.
And here we are passing to arguments.
First of all, property, for example.
And secondly, our object, for example, +1.
In this case, we getting one back.
What we can do here, we can now because it's carried.
Just call it was one argument.
Just proceed.
And as you can see, we getting back a current function.
Now we can store it somewhere and reuse.
For example, we can create here additional function.
Get it.
And we're calling here, get with just property ID.
And now, as you can see in browser, we can use get a D function everywhere across our application
on any object to get a property ID from it.
Now we can do exactly the same with map, for example, here.
I want to create map and they want to carry a map function.
So here we're getting a function, which is an argument of the map and values, which is in the.
And here I want just to call a plain JavaScript values that map and then pass in our function inside.
But now our map is carried, which means we can use it everywhere, like a road map.
For example, we can pass inside our map get ID.
And now here is a second argument we can pass an array and just have here.
ID equals one.
As you can see here, with those actually got an array of IDs with the help of the map and actually
help us to arguments, but we can also carry it.
For example, we can name a function here const get IDs.
And here we want to call our map on Get ID.
In this case, we have a partial applied function, get ideas and we can use it to get ideas from any
array.
For example, here where I write and get IDs and where Colin disfunction on the array was object inside
and we have here a D1.
And as you can see, it is working and this is exactly the need of the current to write JavaScript and
functional way.
And yet this is quite advanced topic.
This is why it is completely fine if you don't know this topic as a beginner, but at least you must
have some basic understanding of what is current and why do you need to tone?