Encontrar el numero menor de 3 campos

by Porfirio Chavez

HTML

<script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
<fieldset>
<label>experian</label>
<input type="text" name="val1" value="5">
<br>
<label>transunion</label>
<input type="text" name="val2" value="10">
<br>
<label>equifax</label>
<input type="text" name="val3" value="15">
<br>
<button type="button">
    Verificar Menor
</button>
</fieldset>

JavaScript

$(function(){
	//cuando se haga click en el boton
	$('button').on('click', function(e){
  
      //creamos una variable vacia para meter los numeros
      var valores = [];
  	//buscar cada input
  	$("input[type=text]").each(function(index) {
    	//obtener su valor, si es nulo, vacio u error, hacerlo cero 
      var valoractual = $(this).val();
      if(isNaN(valoractual)){
        valores.push(0);
      } else {
      	valores.push(parseInt(valoractual));
      }
  	});
    
    //ya que se tienen los valores, buscar el menor
    var minimo = buscarElMinimo(valores);
    
    alert(minimo);
	});
});

function buscarElMinimo(arrayNumeros){
	var minimo = Number.POSITIVE_INFINITY;
	var tmp;
	for (var i=arrayNumeros.length; i>=0; i--) {
    tmp = arrayNumeros[i];
    
    console.warn(tmp);
    
    if(tmp > 0){
    	if (tmp < minimo) minimo = tmp;
    }
	}
  return minimo;
}