gpt4 book ai didi

javascript - 对返回带有许多粗箭头的多个函数的 javascript 函数感到困惑

转载 作者:行者123 更新时间:2023-11-30 13:53:34 27 4
gpt4 key购买 nike

我的计算机作业有问题。我需要访问函数的 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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com