Skip to content

Instantly share code, notes, and snippets.

@jremmen
Last active December 20, 2015 08:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jremmen/6099560 to your computer and use it in GitHub Desktop.
Save jremmen/6099560 to your computer and use it in GitHub Desktop.
js: recursive max and min with partial application
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