Tema: duda Array
Ver Mensaje Individual
  #2 (permalink)  
Antiguo 29/11/2008, 17:37
Avatar de caricatos
caricatos
Moderador
 
Fecha de Ingreso: abril-2002
Ubicación: Torremolinos (Málaga)
Mensajes: 19.607
Antigüedad: 22 años, 10 meses
Puntos: 1284
Respuesta: duda Array

Hola:

Habría que trabajarlo...

Código:
<html>
<head>
<title>
	http://www.caricatos.net/probador
</title>
<script>
Array.prototype.X = function() {
 valores = {};
 mayor = item = 0;
 for (i = 0, total = this.length;i < total; i ++)
  if (valores[this[i]]) valores[this[i]]++;
  else valores[this[i]] = 1;
  for (i in valores) if (valores[i] > mayor) {item = i; mayor = valores[i]};
 return [item, mayor];
}
miArray = new Array()
miArray[0] = 1
miArray[1] = 5
miArray[2] = 8
miArray[3] = 5
miArray[4] = 7
miArray[5] = 6
miArray[6] = 5;

window.onload = function() {r = miArray.X(); alert(r[0] + " aparece " + r[1] + " veces.")}
</script>
</head>
<body>

</body>
</html>
Saludos
__________________
Por favor:
No hagan preguntas de temas de foros en mensajes privados... no las respondo