Skip to content

Instantly share code, notes, and snippets.

@nathansmith
Created May 25, 2011 03:09
Show Gist options
  • Select an option

  • Save nathansmith/990244 to your computer and use it in GitHub Desktop.

Select an option

Save nathansmith/990244 to your computer and use it in GitHub Desktop.
Find min/max of array or multiple params.
// Takes either an array or comma separated
// parameters. Both can be called two ways:
//
// min(1, 2, 3, 4, 5);
// max(1, 2, 3, 4, 5);
//
// OR:
//
// min([1, 2, 3, 4, 5]);
// max([1, 2, 3, 4, 5]);
function min() {
if (Object.prototype.toString.call(arguments[0]) === '[object Array]') {
return Math.min.apply(null, arguments[0]);
}
else {
return Math.min.apply(null, arguments);
}
}
function max() {
if (Object.prototype.toString.call(arguments[0]) === '[object Array]') {
return Math.max.apply(null, arguments[0]);
}
else {
return Math.max.apply(null, arguments);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment