This question is from Douglas Crockford. He askes the students to write a function that takes a binary function, and makes it callable with two invocations. Like : applyf(mul)(5)(6) == 30. Do you know how to write this function?
From Douglas Crockford, one solution is :
But this function is a bit tedious. Not very flexvible. One other method we can use is :
Later we just need to check the number of args, if it's 3, then we execute the binary function and return the result. Otherwise, we continue to read arguments and execute the applyf function.
Sorry! You need to login first to post answer.
- ► What weekend projects have you created?
- ► What's your opinion about Alibaba mooncake incident?
- ► Should a CTO write code?
- ► What does it feel to have a programmer dad or mom?
- ► Should we be worried about the win of AlphaGo?
- ► Why doesn't IBM file legal brief in support of Apple?
- ► What are the big Internet events in 2015?
- ► Will Elon Musk get into drone business?
- ► What does your work cubicle look like?
- ► What are you most afraid of as a programmer?