7 ms·
A lot of these examples are wrong... function double(n) { return 2*n; } map(double, [1,2,3]) //=> [1, 4, 9] should be => [2, 4, 6] function g
by thepicard 13y ago
A lot of these examples are wrong...
function double(n) { return 2*n; }
map(double, [1,2,3])
//=> [1, 4, 9]
should be => [2, 4, 6]
function greaterThan(l, r) {
return l > r;
}
greaterThan(5, 100);
//=> true
should be => false
maybeGT(5)(10000000);
//=> false
Based on your earlier declaration of greaterThan this result is actually correct. The curried application ordering is also correct and flip is unneeded.
schonfinkel(function(a1,a2) {return [a1,a2];})(1)(2);
//=> [1, 2]
I would proofread the rest but I am about to be late for class! =O
Edit: since i'm going to complain I might as well say something nice as well. I did like this article example correctness aside, and I hadn't seen that implementation of pipeline before! Much awesome. =)
- thepicard 13y agoActually, I think the original intent regarding greater than was: greaterThan(100, 5); //=> true That is, l is greater than r, and to then properly curry the arguments do need to be flipped such that maybeGT(5) results in a function that returns whether the argument is greater than 5.
- fogus 13y agoExactly right. We like to be able to do something like: var gtThreshold = gt(100); And then: filter(gtThreshold, array); This is nicely fluent I would say.
- fogus 13y agoSomeone has already addressed the maybeGT case, but you were right about the double problem. I had originally made it a squaring function, but for some dumb reason decided to make it a doubler instead just before submitting. There is a lesson in there about last moment changes. ;-)