implement curry() with placeholder support
2022年5月1日小于 1 分钟
implement curry() with placeholder support
Question
This is a follow-up on 1. implement curry()
please implement curry()
which also supports placeholder.
Here is an example
const join = (a, b, c) => {
return `${a}_${b}_${c}`
}
const curriedJoin = curry(join)
const _ = curry.placeholder
curriedJoin(1, 2, 3) // '1_2_3'
curriedJoin(_, 2)(1, 3) // '1_2_3'
curriedJoin(_, _, _)(1)(_, 3)(2) // '1_2_3'
more to read
https://javascript.info/currying-partials
https://lodash.com/docs/4.17.15#curry
https://github.com/planttheidea/curriable
Code
/**
* @param { (...args: any[]) => any } fn
* @returns { (...args: any[]) => any }
*/
function curry(fn) {
// your code here
}
curry.placeholder = Symbol()