Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// The outrageous totally awesomely unoptimized and hard way of doing
// the stuff :D
(function() {
var c, list
, letters = {}
, str = "ah, yes, for all the letters, you'll need"
+ "a loop... i read it wrong."
;
str.replace(/\s|\S/g, function(match) {
if (match && match[0]) {
c = match[0];
letters[c] = (letters[c] || 0) + 1 }
});
// prints everything...
list = Array.prototype.map.call(Object.keys(letters), function(key) {
return [letters[key],
key + ": " + letters[key]];
});
list.sort();
return list.map(function(i){ return i[1] });
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment