Javascript String frequency()

Description

Javascript String frequency()




String.prototype.frequency = function () {
    if (this.length === 0) return null;
    return this.split("").reduce(function (a, v) {
        if (!a[v]) a[v] = 0;
        a[v]++;//from w ww .  j a v  a  2  s  . c o  m
        return a;
    },{});
};



PreviousNext

Related