Get index from lowest value on array - Node.js Array

Node.js examples for Array:Search

Description

Get index from lowest value on array

Demo Code


/**/* w w w.j a va2  s .c om*/
 * Get index from lowest value on array
 */
Array.prototype.getIndexOfLowerValue = function() {
  return this.getIndex(this.lowest());
}
/**
 * Get lowest value on an array
 */
Array.prototype.lowest = function() {
  var lowest_value = this[0];
  for(var i=1; i<this.length; i++) {
    if(this[i] < lowest_value) {
      lowest_value = this[i];
    }
  }
  return lowest_value;
}

Related Tutorials