We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
To: icyfe
面试公司: 深信服
面试环节: 二面
问题: 实现 go('l')//gol go()('l')//gool go()()()('l');//返回goool
自己的答案:
function go(...arg1) { let str = 'go' var addarg = function (...arg2) { if (!arg2[0]) { str += 'o' //当没有参数时候就累加默认的参数o 并返回当前函数保持对str的引用产生闭包 return addarg } else { return str += arg2[0]//如果是有参数就直接返回最后累加的字符串 } } return addarg(...arg1) } console.log(go('l'));//gol console.log(go()()()()('l'));//goooool
解答思路: 说下基本的思路,这题考察闭包,原理上就是当没有传入参数时就默认是传‘o’然后累加起来返回函数本身,当最后有参数时就返回之前累计的参数拼接字符传返回。 推荐阅读相关文章函数科里化
The text was updated successfully, but these errors were encountered:
icyfe
No branches or pull requests
To:
icyfe
面试公司:
深信服
面试环节:
二面
问题:
实现
go('l')//gol
go()('l')//gool
go()()()('l');//返回goool
自己的答案:
实现如下:
解答思路:
说下基本的思路,这题考察闭包,原理上就是当没有传入参数时就默认是传‘o’然后累加起来返回函数本身,当最后有参数时就返回之前累计的参数拼接字符传返回。
推荐阅读相关文章函数科里化
The text was updated successfully, but these errors were encountered: