Node.js examples for Array:Search
Index of maximum value within array
/**/* w ww.ja v a 2 s . c o m*/ * * @param {Number} start * start position in array * @param {Number} stop * stop position in array * * @return {Number} index of maximum value within array * */ Array.prototype.max = function(start, stop) { start = (start != undefined) ? start : 0; stop = (stop != undefined) ? stop : this.length; var max = start; for (var i=(start+1); i<stop; i++) if (this[i] > this[max]) max = i; return max; };