Javascript Array max()
method
Array.max = function( array ){ return Math.max.apply( Math, array ); };
Array.prototype.max = function() { return Math.max(...this); }
Array.prototype.max = function() { return Math.max(...this); } console.log([1,2,3,4,5].max());//from w ww . j av a 2 s . com
Array.prototype.max = function() { return Math.max.apply(null, this); }; Array.prototype.min = function() { return Math.min.apply(null, this); }; var a = [1,2,3];/* w w w . j ava 2 s . c o m*/ console.log(a.max()); console.log(a.min());
Array.prototype.max = function() { return Math.max.apply(null, this); };
// make max method fluent on instances of Array // [100, -100, 1000, -1000, 0].max() => 1000 Array.prototype.max = function() { return Math.max.apply(null, this) }
Array.prototype.max = function() { return Math.max.apply(null, this) };
Array.prototype.max = function () { return this.reduce((a, b) => Math.max(a, b), Number.NEGATIVE_INFINITY) }
/**//from w ww . j ava 2 s. c o m * Returns the maximum value of the array * @return the maximum value of the array */ Array.prototype.max = function() { return Math.max.apply(Math, this); };
Array.prototype.max = function() { return Math.max.apply(null, this); } var arr = [1, 2, 3] console.log(arr.max())/* ww w . j a va 2 s . c om*/ function findLongestWord(str) { var array = str.split(' '); var longest = 0; for (var i = 0; i < arr.length; i++) { if (array[i].length > longest) { longest = array[i].length; } } return longest; }
function array_max( ){ var i, max = this[0]; for (i = 1; i < this.length; i++) { if (max < this[i]) max = this[i];//from w w w. j av a 2s .c om } return max; } Array.prototype.max = array_max; var x = [ 1, 2, 3, 4, 5, 6] var y = x.max( ); alert(this.y);
function array_max( ) { var i, max = this[0]; for (i = 1; i < this.length; i++) {//from www. ja v a2 s .co m if (max < this[i]) { max = this[i]; } } return max; } Array.prototype.max = array_max; var x = new Array(1, 2, 3, 4, 5, 6); var y = x.max();
Array.prototype.max = function(){ var max = this[0]; this.forEach(function(element, index, array){ if(element > max){ max = element;//from w ww .j av a2 s . co m } }) return max; } var arr1 = [3,6,9,1,5,0,11]; console.log(arr1.max());
//Return Largest Numbers in Arrays Array.prototype.max = function(){ return Math.max.apply(null, this); }; function largestOfFour(arr) { // You can do this! var myArr=[];/*from ww w. j ava 2s. c o m*/ for(var i=0; i<arr.length;i++){ myArr.push(arr[i].max()); } return myArr; } largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]); //result: [5, 27, 39, 1001]
Array.prototype.max = function() { var r = null;//from ww w. ja v a 2 s. com for (var i = 0; i < this.length; i++) { if (r === null || this[i] > r) { r = this[i]; } } return r; };
Array.prototype.max = function () { return this.reduce((a, b) => (a > b ? a : b), Number.MIN_SAFE_INTEGER); };
Array.prototype.max = function(){ var max=this[0]; this.forEach(function(v){max=(v>max)?v:max;}); return max;/*from www .j a v a2 s .c o m*/ };
Array.prototype.max = function() { return Math.max.apply(null, this); }; function largestOfFour(arr) { return arr.map(function(a){ return a.max() });/*from w w w . ja v a 2 s.c om*/ } //without polluting array function largestOfAll(arr) { return arr.map(function(a){ return Math.max.apply(null, a); }); } console.log(largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]])); console.log(largestOfAll([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]));
Array.prototype.max = function(){ return Math.max.apply({}, this); };
Array.prototype.max = function() { return Math.max.apply(null, this); }
Array.prototype.max = function(){ var i, max = this[0]; for (i = 1; i < this.length; i++){ if (max < this[i]) max = this[i];/*from w w w .j a v a 2 s. c o m*/ } return max; };
Array.prototype.max = function() { return this.reduce(function(p, v) { return (p > v ? p : v); });/*from w ww .j a va 2 s . com*/ }
/* Functions to work with arrays more easily */ Array.maxProp = function (array, prop) { var values = array.map(function (el) { return el[prop]; });// w w w . j av a 2 s . co m return values.max() }; Array.sumProp = function (array, prop) { var values = array.map(function (el) { return el[prop]; }); return values.reduce(function (a, b) { return a + b; }, 0); }; Array.prototype.max = function() { return Math.max.apply(null, this); }; Array.avgProp = function (array, prop)?{ var values = array.map(function (el) { return el[prop]; }); return values.avg() } Array.prototype.avg = function(){ var l=this.length var t=0; for(var i=0;i<l;i++){ t+=this[i]; } return Math.floor(t/l); }
// find the max of an array Array.prototype.max = function() { return Math.max.apply(null, this); };
Array.prototype.max = function(){ return this.reduce(function(p,n){ if(n > p || p === null){ return n;/* w ww . j a v a2 s.c om*/ } else { return p; } },null); };
Array.prototype.max = function () { return this.reduce(function(previousValue, currentValue) { return previousValue > currentValue ? previousValue : currentValue; });/*from w w w . j a v a 2s .c om*/ };
/*/*from w ww. j a v a 2 s. c o m*/ * Returns the maximum element of the array. */ Array.prototype.max = function () { return Math.max.apply (null, this); };