Skip to content

Instantly share code, notes, and snippets.

@jezinka

jezinka/main.js Secret

Created Jun 16, 2017
Embed
What would you like to do?
Array.prototype.byCount = function () {
var itm, a = [], L = this.length, o = {};
for (var i = 0; i < L; i++) {
itm = this[i];
if (!itm) continue;
if (o[itm] == undefined) o[itm] = 1;
else ++o[itm];
}
for (var p in o) a[a.length] = p;
return a.sort(function (a, b) {
if (o[b] !== o[a]) {
return o[b] - o[a];
}
return a.charCodeAt(0) - b.charCodeAt(0);
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment