-
-
Save jezinka/f52e266a80ea42a652ef8664c34e43bf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 a = []; | |
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