Nodejs Array Max maximum()

Here you can find the source of maximum()

Method Source Code

/*/* w ww . ja va  2  s .co m*/
 * Extends array object with a function to retrieve the maximum value from an array
 * Requirement : Array only contains integers
 **/
Array.prototype.maximum = function()
{
    var max = this[0];
    for(el in this)
    {
        if(this[el] > max)
        {
            max = this[el] ;
        }
    }
    return max ;
};

Related

  1. max(s)
    Array.prototype.max = function (s) {
      s = s || Selector;
      var l = this.length;
      var max = s(this[0]);
      while (l-- > 0)
        if (s(this[l]) > max) max = s(this[l]);
      return max;
    };
    
  2. max(selector)
    Array.prototype.max = function(selector){
      var maxItem = this[0];
      var maxValue = -999999;
      this.forEach(function(item){
        var value = selector(item);
        if( value > maxValue ){
          maxItem = item;
          maxValue = value;
      });
      return maxItem;
    
  3. maxima()
    Array.prototype.maxima = function() {
      for(var i = 0, maxValue = Number.MIN_VALUE; i < this.length; i++) {
        parseInt(this[i]) > maxValue && (maxValue = this[i]);
      return maxValue
    var arr = [1,21,3,4,22,45,6,7,32];
    console.log(arr.join("|") + ":" + arr.maxima());
    
  4. maxima()
    Array.prototype.maxima = function(){
      for (var i = 0, maxValue = Number.MIN_VALUE; i < this.length; i++) {
        parseInt(this[i]) > maxValue &&  (maxValue = this[i])
      };
      return maxValue
    var arr = [1,21,3,4,22,45,6,7,32];
    console.log(arr.join("+")+"="+arr.sum());
    console.log(arr.join("|")+" "+arr.maxima());
    ...
    
  5. maximum()
    'use strict';
    Array.prototype.maximum = function () {
      return this.reduce(function (max, aValue) {
        return Math.max(max, aValue);
      }, this[0]);
    };