Nodejs Array Min min(comparer)

Here you can find the source of min(comparer)

Method Source Code

Array.prototype.min = function(comparer) {

    if (this.length === 0) return null;
    if (this.length === 1) return this[0];

    comparer = (comparer || Math.min);

    var v = this[0];
    for (var i = 1; i < this.length; i++) {
        v = comparer(this[i], v);/* w ww  . jav  a2 s.com*/
    }

    return v;
}

Related

  1. min()
    Array.prototype.min = function () {
        var min = this[0];
        var len = this.length;
        for (var i = 1; i < len; i++) if (this[i] < min) min = this[i];
        return min;
    
  2. min()
    Array.prototype.min = function() {
        var length = this.length;
        var min = this[0];
        for ( var i = 0; i < length; i++ ) {
            var elem = this[i];
            if ( elem < min ) min = elem;
        return min;
    
  3. min()
    Array.prototype.min = function() {
      var min = Infinity;
      for (var i = 0; i < this.length; i++) {
        if (typeof this[i] === "number" && this[i] < min) {
          min = this[i];
      return min;
    };
    ...
    
  4. min()
    Array.prototype.min = function() {
      if (this.toNumsOnly().length == 0) return undefined;
      return Math.min.apply(null, this.toNumsOnly());
    };
    
  5. min(array)
    Array.min = function( array ){
        return Math.min.apply( Math, array );
    };
    
  6. min(fun)
    Array.prototype.min = function (fun) {
        var min = this[0];
        this.forEach(x => {
            if (fun ? fun(min, x) : (min < x))
                min = x;
        });
        return min;
    };
    
  7. min(funObjectiveValue)
    Array.prototype.min = function (funObjectiveValue) {
        var result = null;
        var min = Number.MAX_VALUE;
        for (var i = 0; i < this.length; i++) {
            var val = funObjectiveValue(this[i]);
            if (val < min) {
                result = this[i];
                min = val;
        return result;
    };
    
  8. min(func)
    Array.prototype.min = function (func) {
        return func === undefined ? Math.min.apply(null, this) : Math.min.apply(null, this.select(func));
    };
    
  9. min(k)
    Array.prototype.min = function (k) {
      return Math.min.apply (null, this.column (k));
    };