Ver Mensaje Individual
  #11 (permalink)  
Antiguo 18/02/2015, 05:39
merops
 
Fecha de Ingreso: enero-2015
Mensajes: 33
Antigüedad: 9 años, 4 meses
Puntos: 0
Respuesta: array ordenado con javascript

hola os dejo lo que he hecho
asi si funciona

Cita:
<!DOCTYPE html>
<html>
<head>
<title>Ejemplo de Ordenar Array de Mayor a Menor</title>
<meta charset="utf-8">
<style type="text/css">
#call {
background: teal;
border-radius: 1em;
padding: 1em;
font-weight: bold;
text-align: center;
width: 10em;
}
</style>

<script type="text/javascript">
window.onload = function () {
document.getElementById('call').onclick = addNumber;
}

function addNumber () {
// Variable a Utilizar.
var arrNums = new Array();
var num;

// Bucle hasta que se indique una N.
while ( num != "N" ) {
num = prompt(arrNums.length + 1 + " Introduce un número. Si deseas acabar introduce N.");
if ( !isNaN(parseInt(num)) ) {
arrNums.push(num);
}
}

// Ordenando de Mayor a Menor y Mostrando.
alert( arrNums.sort(function(a, b) {return b-a}) );

}
</script>

</head>
<body>
<div id="call">Mostrar Prompt</div>
</body>
</html>

asi me lo ha dado de paso
un saludo y muchas gracias