|
|
|
|
|
by PySlice
4772 days ago
|
|
If programmers of functional languages were better at naming things, it would be easy. Let's rename g to callTwice and h to aFunction: function callTwice(aFunction) {
return function(y) {
return aFunction(aFunction(y));
};
}
function square(x) { return x*x; }
var squareTwice = callTwice(square);
81 === squareTwice(3);
|
|
Also, the names you gave don't help at all, as the idea of calling those g and h is to treat them anonymously. By calling it "callTwice", you are thinking about it as some sort of utility function, which is not the case. Shows you didn't grasped the idea behind it yet.