对javascript函数返回带有多个粗箭头的多个函数感到困惑 [英] Confused about javascript function returning multiple functions with many fat arrow
本文介绍了对javascript函数返回带有多个粗箭头的多个函数感到困惑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的CS作业有问题.
我需要访问该函数的x
值,但是我的代码向我返回了一个空函数,而不是带有值的
I have problem with my cs homework.
I need to access the x
value of the function, but my codes is returning me an empty function instead of with the values
我已经用Google搜索了所有的currying和closes,但是它们都不先进,足以帮助我解决问题
I have googled all the currying and closures, but none of them are advanced enough to help me solve my problem
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
当我尝试所有组合时,我的控制台会不断返回我functions
my console keeps returning me functions
instead when I try all the combinations
function(a,b){return a;}
推荐答案
您可以像这样更改head
函数:
You could change head
function like this:
const pair = (x, y) => f => f(x, y);
const head = f => f(a => a)
console.log(head(pair(1,2)))
这篇关于对javascript函数返回带有多个粗箭头的多个函数感到困惑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文