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?
change variables names
Array.prototype.byCount = function () {
var array_length = this.length, dict = {};
for (var i = 0; i < array_length; i++) {
var letter = this[i];
if (!letter) {
continue
}
if (dict[letter] === undefined) {
dict[letter] = 1
} else {
++dict[letter]
}
}
var keys = Object.keys(dict);
return keys.sort(function (a, b) {
if (dict[b] !== dict[a]) {
return dict[b] - dict[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