Nodejs Array Get Max getMaxNumber()

Here you can find the source of getMaxNumber()

Method Source Code

var arr = [72, 23,90, 354, 3, 10]

Array.prototype.getMaxNumber = function() {
   var max = this[0]
   this.map(function(value){
      max = Math.max(max, value)//  w  w  w . j a v a 2s . c  o m
   })
   return max
}

Array.prototype.getMinNumber = function() {
   var min = this[0]
   this.map(function(value){
      min = Math.min(min, value)
   })
   return min
}

Array.prototype.alert = function(){
   this.map(function(value){
      debug('alert : ' + value)
   })
}

debug(arr.getMaxNumber())
debug(arr.getMinNumber())
arr.alert()

var arr = [
  {a:1, c:2, d:3, f:5, e:2},
  {a:1},
  {a:1, b:2, c: 3},
  {a:1, b:2}
];

var soarr = arr.sort(function(a, b){
   var n1 = 0
   var n2 = 0
   for (var i in a)
      n1 ++
   for (var j in b)
      n2 ++
   return n1 < n2 ? -1 : 1
})

Related

  1. getMAX()
    Array.prototype.getMAX = function(){
      var max = this[0];
      for(var i = 1; i < this.length; i++){
        if(this[i] > max){
          max = this[i];  
      return max;
    var array = new Array();
    array[0] = 12;
    array.push(12,34,56,78,21,53,10);
    document.write(array.getMAX());
    
  2. getMax()
    Array.prototype.getMax = function() {
      var max = this[0];
      for (var x = 1; x < this.length; x++) {
        if (this[x] > max) {
          max = this[x];
      return max;
    };
    ...
    
  3. getMax()
    Array.prototype.getMax = function(){
      var temp = 0;
      for(var x=1; x<this.length; x++){
        if(this[x]>this[temp]){
          temp = x;
      return this[temp];
    
  4. getMax()
    Array.prototype.getMax = function(){
        var arr = this;
        var maxN = arr[0];
        for(var ar in arr){
            if(arr[ar] >= maxN){
                maxN = arr[ar];
        return maxN;
    ...
    
  5. getMax()
    Array.prototype.getMax=function(){
      var max=0;
      for(var i=0;i<this.length;i++){
        max=this[i]>max?this[i]:max;
      return max;