http://jsfiddle.net/s0f57q82/    
Código Javascript
:
Ver originalString.prototype.contar = function() {
    var c = {};
    this.toLowerCase().replace(/[^a-záéíóúüñ ]+/ig, ' ').replace(/\s+/g, ' ').replace(/(^\s+)|(\s+$)/,'').split(" ").forEach(function(p){
        c[p] = (p.length && c[p] ? c[p] + 1 : 1);
    });
    return c;
};
  
Otra muy parecida a la anterior que tenía hecha de hace tiempo.