Nodejs Array Max Matrix maxChildren(childrenPos)

Here you can find the source of maxChildren(childrenPos)

Method Source Code

Array.prototype.maxChildren = function(childrenPos) {
  if (childrenPos.length == 1) {
    return childrenPos[0];
  }//from  w ww.ja  v  a 2s  .c  o  m

  if (this[childrenPos[0]] >= this[childrenPos[1]]) {
    return childrenPos[0];
  } else {
    return childrenPos[1];
  }
}

Related

  1. matrix(rows, cols, initial)
    Array.prototype.matrix = function (rows, cols, initial) {
        var arr = [];
        for (var i = 0; i < rows; i++) {
            var columns = [];
            for (var j = 0; j < cols; j++) {
                columns[j] = initial;
            arr[i] = columns;
        return arr;
    var matrix = [].matrix(3, 3, 10);
    console.log(matrix);
    arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
    result = arr.reduceRight(function reduce(sum, value) {
        return "" + sum + value;
    });
    console.log(result);
    
  2. max2d( si, ei, sj, ej, calc_maxm, update_array )
    Array.prototype.max2d = function ( si, ei, sj, ej, calc_maxm, update_array ) {
      var maxm = 0.0;
      for ( var ip = si; ip <= ei; ip++ ) {
        for ( iq = sj; iq <= ej; iq++ ) {
          if ( calc_maxm ) {
            this[ip][iq] = calc_maxm.call(this,this[ip][iq]);
          if ( this[ip][iq] > maxm ) {
            maxm = this[ip][iq];
    ...