Javascript Array min()

Description

Javascript Array min()

Array.min = function( array ){
    return Math.min.apply( Math, array );
};

Javascript Array min()



Array.prototype.min = function() {
  return Math.min.apply(null, this);
};

Javascript Array min()

// make min method fluent on instances of Array
// [100, -100, 1000, -1000, 0].min() => -1000

Array.prototype.min = function() {
  return Math.min.apply(null, this)
}

Javascript Array min()

/**//from   w  w  w.ja v a  2  s. c om
 * Returns the minimum value of the array
 * @return the minimum value of the array
 */
Array.prototype.min = function() {
  return Math.min.apply(Math, this);
};

Javascript Array min()

Array.prototype.min = function() {
  var min = this[0];
  for (var i = 1; i < this.length; i++) if (this[i] < min) min = this[i];
  return min;//  w  w  w  . j  av  a2 s  . c  o  m
}

Javascript Array min()

Array.prototype.min = function () {
    var min = this[0];
    for(var i=0;i<this.length;i++){
        if(this[i]<min){
            min = this[i];/*from  w w  w  . j a  v a  2s  .c  o  m*/
        }
    }
    return min;
};

var arr =[10,5,5,30];
var total =0;
var total2 =0;
for(var i in arr){
    if(arr.hasOwnProperty(i)){
        var x = parseInt(arr[i],10);
        total += parseInt(arr[i],10);
    }
}

for(var i=0;i<arr.length;i++){
    total2+=arr[i];
}


console.log(total);
console.log(total2);

Javascript Array min()

Array.prototype.min = function() {
  var r = null;//from   w  ww .j  av a2 s .  c o m
  for (var i = 0; i < this.length; i++) {
    if (r === null || this[i] < r) {
      r = this[i];
    }
  }
  return r;
};

Javascript Array min()

Array.prototype.min = function(){
    var i, min = this[0];
    for (i = 1; i < this.length; i++){
        if (min > this[i])
            min = this[i];/*ww  w .  j a  v a 2s . c  o m*/
    }
    return min;
};

Javascript Array min()

Array.prototype.min = function() {
  return Math.min.apply(null, this);
};

Array.prototype.transpose = function() {
  var a = this,/*from   w  ww .j  a v a  2 s.  c o  m*/
    w = a.length ? a.length : 0,
    h = a[0] instanceof Array ? a[0].length : 0;
  if(h === 0 || w === 0) { return []; }
  var i, j, t = [];
  for(i=0; i<h; i++) {
    t[i] = [];
    for(j=0; j<w; j++) {
      t[i][j] = a[j][i];
    }
  }
  return t;
};

function is_square(matrix)
{
 m=matrix.length;
 for(var i=0 ; i<m; i++)
 {
  if(matrix[i].length!= m)
  {
   return -1;
   i=999999999999;
  }
  
 }
}

Javascript Array min()

Array.prototype.min = function() {
 return this.reduce(function(p, v) {
  return (p < v ? p : v);
 });/*from w w w.  j av a2s  .  c  o m*/
}

Javascript Array min()

Array.prototype.min = function(){
 return this.reduce(function(p,n){ 
  if(n < p || p === null ){ 
   return n;// w w  w  .java  2 s  .c  o  m
  } else {
   return p;
  }
 },null);
};

Javascript Array min()

Array.prototype.min = function () {
    return this.reduce(function(previousValue, currentValue) {
        return previousValue < currentValue ? previousValue : currentValue;
    });//w  w  w.  ja  v a  2  s . c  o  m
};



PreviousNext

Related