Write a `partial(fn, ...presetArgs)` function that pre-fills some arguments of `fn`.
Problem Statement
Write a `partial(fn, ...presetArgs)` function that pre-fills some arguments of `fn`.
Complexity
Time Complexity: -
Space Complexity: -
Hints
š” Hint 1:
Partial application fixes some arguments and returns a new function for the rest.
š” Hint 2:
Return a function that takes the remaining args and calls fn with all args.
š” Hint 3:
return (...laterArgs) => fn(...presetArgs, ...laterArgs);
ā
Solution:
```javascript
function partial(fn, ...presetArgs) {
return (...laterArgs) => fn(...presetArgs, ...laterArgs);
}
```