Skip to content

Instantly share code, notes, and snippets.

@scpike
Last active October 26, 2015 14:43
Show Gist options
  • Save scpike/075207c3451ddeec231d to your computer and use it in GitHub Desktop.
Save scpike/075207c3451ddeec231d to your computer and use it in GitHub Desktop.
(function (x) {
var tokens = x.split(/[\s]/mi);
var occ = {};
tokens.forEach(function(tok) {
var clean = tok.toLowerCase().trim().replace(/[^\w\d\/]/, '');
if (occ[clean]) {
occ[clean] += 1;
} else {
occ[clean] = 1;
}
});
var sortable = [];
for (var x in occ) { sortable.push([x, occ[x]])};
res = "";
sortable.sort(function(a, b) {return b[1] - a[1]}).forEach(function(x) {
res += x[0] + "\t" + x[1] + "\n";
});
return res;
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment