implement _.partial()
2022年5月1日小于 1 分钟
implement _.partial()
Question
_.partial() works like Function.prototype.bind() but this
is not bound.
please create your own partial()
const func = (...args) => args
const func123 = partial(func, 1,2,3)
func123(4)
// [1,2,3,4]
It should also support placeholder.
const _ = partial.placeholder
const func1_3 = partial(func, 1, _, 3)
func1_3(2,4)
// [1,2,3,4]
Code
/**
* @param {Function} func
* @param {any[]} args
* @returns {Function}
*/
function partial(func, ...args) {
// your code here
}