Hola de nuevo
Después después de corregir el error de la "ñ", he caido en la cuenta
que lo mismo le sucede a las vocales acentuadas,vuelvo ha enviar
el script corregiendo estos errores. Creo que ahora va bien.
<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=="á"?"a{":str=="é"?"e{":str=="í"?"i{":str=="ó "?"o{":str=="ú"?"u{":str=="ñ"?"n{":"n{"
return (str)
}
)
//Sustituimos las vocales acentuadas y la ñ (mayusculas)
temp_array[ctr] = temp_array[ctr].toString().replace(/Á|É|Í|Ó|Ú|Ñ/g,function (str,offset,s) {
str =str=="Á"?"A{":str=="É"?"E{":str=="Í"?"I{":str=="Ó "?"O{":str=="Ú"?"U{":str=="Ñ"?"N{":"N{"
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","tu","niño" ,"v","u","ú","NIÑO","áó","áo","zapato","opera","ó" ,"ñu","ÑU","niña","a","No a la guerra!!","Ñ","ñ","nana","caSa","exposicion","o"," ó","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>
Saludos