Skip to content

Instantly share code, notes, and snippets.

@gaand
Created October 5, 2015 19:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gaand/64555f89cf76825447a5 to your computer and use it in GitHub Desktop.
Save gaand/64555f89cf76825447a5 to your computer and use it in GitHub Desktop.
Max
var max = function max() {
  // grab the first number to compare against
  // this will be undefined if arguments is empty
  var maxValue = arguments[0];
  // loop through the remaining numbers
  for (var i = 1; i < arguments.length; i++) {
    // if the current element is greater
    // than the maxValue
    if (arguments[i] > maxValue) {
      // replace maxValue with the current number
      maxValue = arguments[i];
    }
  }

  // return the result
  return maxValue;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment