Nodejs Array Max max(s)

Here you can find the source of max(s)

Method Source Code

Array.prototype.max = function (s) {
   s = s || Selector;//from www .  j a v a 2 s .c om
   var l = this.length;
   var max = s(this[0]);
   while (l-- > 0)
      if (s(this[l]) > max) max = s(this[l]);
   return max;
};

Related

  1. max(comparer)
    Array.prototype.max = function(comparer) {
        if (this.length === 0) return null;
        if (this.length === 1) return this[0];
        comparer = (comparer || Math.max);
        var v = this[0];
        for (var i = 1; i < this.length; i++) {
            v = comparer(this[i], v);
        return v;
    ...
    
  2. max(fun)
    Array.prototype.max = function (fun) {
        var max = this[0];
        this.forEach(x => {
            if (fun ? fun(max, x) : (max < x))
                max = x;
        });
        return max;
    };
    
  3. max(func)
    Array.prototype.max = function (func) {
        return func === undefined ? Math.max.apply(null, this) : Math.max.apply(null, this.select(func));
    };
    
  4. max(k)
    Array.prototype.max = function (k) {
      return Math.max.apply (null, this.column (k));
    };
    
  5. max(prop)
    Array.prototype.max = function (prop) {
        var max = prop ? this[0][prop] : this[0];
        var len = this.length;
        for (var i = 1; i < len; i++) {
            var item = prop ? this[i][prop] : this[i];
            if (item > max) {
                max = item;
        return max;
    };
    
  6. 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;
    
  7. 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());
    
  8. 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());
    ...
    
  9. maximum()
    'use strict';
    Array.prototype.maximum = function () {
      return this.reduce(function (max, aValue) {
        return Math.max(max, aValue);
      }, this[0]);
    };