Consider the following function definitions:
var m1 = function (ns) { return (fp.isGT(fp.hd(ns),fp.hd(fp.tl(ns)))) ? fp.hd(ns) : fp.hd(fp.tl(ns)); }; var m2 = function (ns) { return (fp.isLT(fp.hd(ns),fp.hd(fp.tl(ns)))) ? fp.hd(ns) : fp.hd(fp.tl(ns)); }; var m3 = function (ns) { return fp.add(fp.hd(ns),fp.hd(fp.tl(ns))); }; var g = function (ns,f) { return fp.reduce( function (x,y) { return x + y; }, fp.map(f,ns), 0 ); };
We then make the following three function calls:
g( [[1,2], [3,4], [5,6]] , m1 ); g( [[1,2], [3,4], [5,6]] , m2 ); g( [[1,2], [3,4], [5,6]] , m3 );
Which one of the following values is not one returned by these function calls?
The ( ... ? ... : ... ) conditional ternary operator works like the one that you already know in Java.
Describe what each one of the m1, m2 and m3 functions does on its own.
What does fp.map(f,ns) evaluate to in each function call?
Now put it all together with the folding pattern.