It looks like your second solution is wrong, at least according to the requirements.
const functionCurrying = function(...fns) {
return (param) => {
return fns.reduceRight( (partial, currentFn) => {
return currentFn(partial);
}, param);
};
}
I've changed some names, sorry. I tried to keep that to a minimum. The problems are:
fns
(args
in your version) with ...
that already gives you an Array. You don't need Array.from
.reduceRight
instead of reverse
+ reduce
. Not really an error but preferable.current
(currentFn
in my version) -the function of the current iteration-, you're trying to call args
-the whole array of functions- as a function.In an unrelated note, the question doesn't really seem to be about currying. I didn't change the name of your function to avoid adding more noise, but I would suggest calling it compose
.
Finally, no, I wouldn't consider this an appropriate question for a junior position, unless there were special circumstances.