Skip to content

CodeNot attempted

Partial application

Difficulty: easy

partial(fn, ...preset) returns a function that calls fn with the preset arguments followed by the new ones, keeping this. How is this different from curry?

Show reference solution
export function partial<R>(fn: (...args: any[]) => R, ...args: any[]): (...moreArgs: any[]) => R {
return function (this: unknown, ...moreArgs: any[]) {
return fn.apply(this, [...args, ...moreArgs]);
};
}
Loading editor…