Ver Mensaje Individual
  #11 (permalink)  
Antiguo 13/06/2012, 08:28
Avatar de Aijoona
Aijoona
Colaborador
 
Fecha de Ingreso: mayo-2011
Ubicación: Buenos Aires
Mensajes: 779
Antigüedad: 13 años
Puntos: 343
Respuesta: Array ordenar y eliminar duplicados

No entendí bien, pero vamos a ver:

Código Javascript:
Ver original
  1. var list = ['Perro', 'Perro', 'Gato', 'perrito', 'gatito', 'gatito'];
  2.  
  3. var anotherList = list
  4.     .reduce(function(memo, current) {
  5.         if(memo.indexOf(current) === -1) {
  6.             memo.push(current);
  7.         }
  8.         return memo;
  9.     }, [])
  10.     .sort(function(one, another) {
  11.         return one.toLowerCase() >
  12.             another.toLowerCase() ?
  13.             1 : -1;
  14.     });
  15.    
  16.    
  17. anotherList; // ["gatito", "Gato", "perrito", "Perro"]

PD: Hacer eso que hice en PHP es mucho más díficil.
__________________
blog | @aijoona