Ver Mensaje Individual
  #26 (permalink)  
Antiguo 13/12/2004, 20:54
kepawe
 
Fecha de Ingreso: agosto-2004
Mensajes: 157
Antigüedad: 19 años, 8 meses
Puntos: 5
Hola de nuevo

Cita:
Iniciado por Caricatos
Muchas gracias por enseñarme cosas nuevas.
De nada, Caricatos. Yo también estoy aprendiendo gracias a vosotros.

He utilizado la idea de encriptar de furoya, pero utilizando expresiones regulares.

Cita:
Iniciado por furoya
la palabra "maña" se convierte en "maoa", se ordena, y luego se vuelve a "maña"; "año" quedaría como "aop", porque el agregado de la "ñ" desplaza todo el resto del alfabeto un lugar.
He probado el script, parece que funciona pero puede que se me haya escapado algo.

<html>
<head>
<title>spanish_sort( )</title>
<script language=JavaScript type=text/javascript>
<!--

Array.prototype.spanish_sort = function(){
//Creamos este array para copiar los elementos del array
var temp_array = new Array()
// Poblamos el array temp_array con los elementos de array queremos ordenar
for(var ctr = 0; ctr < this.length ; ctr++){
temp_array[ctr] = this[ctr]
// Sustituimos las vocales acentuadas y la ñ (mininusculas)
temp_array[ctr] = temp_array[ctr].toString().replace(/á|é|í|ó|ú|ñ/g,function (str,offset,s) {
str =str=="á"?"ab":str=="é"?"ef":str=="í"?"ij":str=="ó "?"op":str=="ú"?"uv":str=="op"?"":"op"
return (str)
}
)
//Sustituimos las vocales acentuadas y la ñ (mayusculas)
temp_array[ctr] = temp_array[ctr].toString().replace(/Á|É|Í|Ó|Ú|Ñ/g,function (str,offset,s) {
str =str=="Á"?"AB":str=="É"?"EF":str=="Í"?"IJ":str=="Ó "?"OP":str=="Ú"?"UV":str=="OP"?"":"OP"
return (str)
}
)
}
// ordenamos alfabeticamente
var sc = true
var lg = temp_array.length
while(sc &&(--lg > 0)){
sc= false
for(var i =1; i<= lg; i++){
if(temp_array[i-1] > temp_array[i]){
tmp = temp_array[i -1]
tmpo = this[i-1]
temp_array[i-1] = temp_array[i]
this[i-1] = this[i]
temp_array[i] = tmp
this[i] = tmpo
sc= true
}

}

}

}



//-->
</script>

</head>
<body>
<script language=JavaScript type=text/javascript>
<!--
var myarray = new Array("Zapato","NIÑA","1&1",1,333,"AL","niño","NIÑ O","áó","áo","zapato","ñu","ÑU","niña","a","No a la guerra!!","Ñ","ñ","nana","caSa","exposicion","No a la GUERRA!!","tú","té","tílde","toldo","exposición"," A")
var show = ""
var show1 =""
var show2 =""

for(var ctr = 0; ctr < myarray.length; ctr++){

show += myarray[ctr] + "<br>"

}


myarray.sort()

for(var ctr = 0; ctr < myarray.length; ctr++){

show1 += myarray[ctr] + "<br>"

}

myarray.spanish_sort()
for(var ctr = 0; ctr < myarray.length; ctr++){

show2 += myarray[ctr] + "<br>"

}
//-->
</script>

<table border="1">
<tr>
<td><b>ARRAY ORIGINAL</b></td>
<td><b>MÉTODO sort( )</b></td>
<td><b>MÉTODO spanish_sort( )</b></td>

</tr>
<tr>
<td><script>document.write(show)</script></td>
<td><script>document.write(show1)</script></td>
<td><script>document.write(show2)</script></td>
</tr>
</table>
</body>
</html>

Furoya, no entiendo bien lo de "Con respecto al comenterio sobre el otro forero....", pero creo que sepamos mucho o poco de un tema, todos aportamos algo.

Saludos