Skip to content

Instantly share code, notes, and snippets.

@robotlolita
Created September 21, 2010 19:29
Show Gist options
  • Save robotlolita/590356 to your computer and use it in GitHub Desktop.
Save robotlolita/590356 to your computer and use it in GitHub Desktop.
// 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