Ver Mensaje Individual
  #8 (permalink)  
Antiguo 24/12/2014, 11:34
Avatar de marlanga
marlanga
 
Fecha de Ingreso: enero-2011
Ubicación: Murcia
Mensajes: 1.024
Antigüedad: 13 años, 4 meses
Puntos: 206
Respuesta: Contar palabras repetidas

http://jsfiddle.net/s0f57q82/

Código Javascript:
Ver original
  1. String.prototype.contar = function() {
  2.     var c = {};
  3.     this.toLowerCase().replace(/[^a-záéíóúüñ ]+/ig, ' ').replace(/\s+/g, ' ').replace(/(^\s+)|(\s+$)/,'').split(" ").forEach(function(p){
  4.         c[p] = (p.length && c[p] ? c[p] + 1 : 1);
  5.     });
  6.     return c;
  7. };

Otra muy parecida a la anterior que tenía hecha de hace tiempo.