In this article we will be solving one question which uses currying and some array methods.
So, here we have some requirements to solve this question:
1) We have to check arguments length
2) We have to replace the "_", placeholder.
So, we have to write code inside function curry(as shown in question above.)
So, here in function "curry" we had passed "func" as an argument.
and acc to this question this argument "func" is the join function.
Now, there may be a condition in which there are arguments coming to the function more than the expected function's length.
So, we don't want extra args, here we have used the splice method.
which is splicing the args from 0th position to the length of func(i.e., join here)
=> args.splice(0, func.length)
Now we need to check if the placeholder(i.e., "_" in this case) is present or not
Now, there maybe the condition where there is no placeholder present and the length is also equal to the expected length.
And now the worst can happen is there is the presence of the placeholders and now we need to replace them in order to obtain expected output.
So, we need to iterate over the args to check the presence of the placeholders.
Here's the complete code.
I hope it helps :)
Follow for more such contents
Top comments (0)