Skip to content

Instantly share code, notes, and snippets.

@jezinka

jezinka/main.js Secret

Created June 16, 2017 15:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jezinka/14eb9d60e013e2876f233778e60dede5 to your computer and use it in GitHub Desktop.
Save jezinka/14eb9d60e013e2876f233778e60dede5 to your computer and use it in GitHub Desktop.
Array.prototype.byCount = function () {
var L = this.length, o = {};
for (var i = 0; i < L; i++) {
var itm = this[i];
if (!itm) {
continue
}
if (o[itm] === undefined) {
o[itm] = 1
} else {
++o[itm]
}
}
var keys = Object.keys(o);
return keys.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