我的计算机作业有问题。
我需要访问函数的 x
值,但我的代码返回一个空函数而不是值
我用谷歌搜索了所有的柯里化(Currying)和闭包,但它们都不够先进,无法帮助我解决问题
const pair = (x, y) => f => f(x, y); // Do not edit this function
const head = p => //Answer here
console.log(head(pair(1,2))) // Do not edit this
当我尝试所有组合时,我的控制台一直返回函数
function(a,b){return a;}
最佳答案
你可以这样改变 head
函数:
const pair = (x, y) => f => f(x, y);
const head = f => f(a => a)
console.log(head(pair(1,2)))
关于javascript - 对返回带有许多粗箭头的多个函数的 javascript 函数感到困惑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57736496/