Design & Download
Your JS Library
in Seconds!!!

Snippet: min() & max()

Written by Christopher West (cwest) on January 12, 2016.
Find the minimum and maximum values.
function min(x) {
  return Math.min.apply(x, isArrayLike(x) ? x : arguments);
}

function max(x) {
  return Math.max.apply(x, isArrayLike(x) ? x : arguments);
}

min(...) API Documentation

Get the minimum value.

Parameters

  1. x {Array|number}:
    If this is an array, the minimum value within this array will be sought. If this is a number, it will be compared to all subsequent parameters to find which is the minimum value.
  2. ...otherValues {number=}:
    If x is not an array, all of these values will be compared to x and to each other to find the minimum value.

Returns

The minimum value found.

max(...) API Documentation

Get the maximum value.

Parameters

  1. x {Array|number}:
    If this is an array, the maximum value within this array will be sought. If this is a number, it will be compared to all subsequent parameters to find which is the maximum value.
  2. ...otherValues {number=}:
    If x is not an array, all of these values will be compared to x and to each other to find the maximum value.

Returns

The maximum value found.