Last active
December 20, 2015 08:19
-
-
Save jremmen/6099560 to your computer and use it in GitHub Desktop.
js: recursive max and min with partial application
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var max = reduce(function(a, b) { return a > b; }); | |
var min = reduce(function(a, b) { return a < b; }); | |
function reduce(p) { | |
return function(a) { | |
function iter(a, c) { | |
if(a.length === 0) return c; | |
else return iter(a.slice(1), p(a[0], c) ? a[0] : c); | |
} | |
return iter(a.slice(1), a[0]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment