Nodejs Array Max max()

Here you can find the source of max()

Method Source Code

/**// w ww  .j ava  2  s.co  m
@Name: Array.prototype.max
@Author: Paul Visco
@Version: 1.1 11/19/07
@Description: Finds the maximum value in an alpha/numeric array.  Sorts alphanumerically and chooses the highest.  Number have preference over letters, so 1 is higher than 'apple'

@Return: String/Number Returns the max value
@Example:
var myArray = [5, 10, 15];
var answer = myArray.max();
//answer = 15;
*/
Array.prototype.max = function(){
    var max=this[0];
    this.forEach(function(v){max=(v>max)?v:max;});
    return max;
};

Related

  1. max()
    var min = Math.min.apply(null, arr),
        max = Math.max.apply(null, arr);
    Array.prototype.max = function() {
      return Math.max.apply(null, this);
    };
    
  2. max()
    Array.prototype.max = function () {
      return Math.max.apply(Math, this);
    
  3. max()
    Array.prototype.max = function() {
      return Math.max.apply(null, this);
    };
    
  4. max()
    Array.prototype.max = function() {
      return Math.max.apply(Math, this);
    };
    
  5. max()
    Array.prototype.max = function() {
      var r = null;
      for (var i = 0; i < this.length; i++) {
        if (r === null || this[i] > r) {
          r = this[i];
      return r;
    };
    ...
    
  6. max()
    Array.prototype.max = function() {
      var max = this[0];
      var len = this.length;
      for (var i = 1; i < len; i++){
        if (this[i] > max) {
          max = this[i];
      return max;
    ...
    
  7. max()
    Array.prototype.max = function() {
      return this.reduce(function(p, v) {
        return (p > v ? p : v);
      });
    
  8. max()
    Array.prototype.max = function(){
        var i, max = this[0];
        for (i = 1; i < this.length; i++){
            if (max < this[i])
                max = this[i];
        return max;
    };
    
  9. max()
    Math.clamp = function(val, min, max) {
        return Math.max(Math.min(val, max), min);
    };
    Array.prototype.max = function() {
        return Math.max.apply(null, this);
    Array.prototype.min = function() {
        return Math.min.apply(null, this);