JSFiddle - React, Tailwind, and code Playground

JavaScript

String.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;
};
var txt = "Texto de control. No me jodas  carabanchel de españa españa de españa  ";


console.log(txt.contar());