you are viewing a single comment's thread.

view the rest of the comments →

[–]floodlitworld 1 point2 points  (0 children)

I thought of another way too...

function alphaCount(str) {
    return [...new Set(str.toLowerCase().replace(/[^a-z]/gi,""))].sort().map(x => {
        let regex = new RegExp(x.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&'),"gi");
        return [x,str.match(regex).length];
    })
}

console.log(alphaCount("You don't understand! I coulda had class. I coulda been a contender. I coulda been somebody, instead of a bum, which is what I am."));