Word frequency analysis
# StatsFind most frequent words in a sentence
$ echo "the cat sat on the mat and the cat purred" | word-freq (input) => {
const freq = {};
input
.toLowerCase()
.split(/[^a-zA-Z0-9']+/)
.filter((w) => w.length > 1)
.forEach((w) => (freq[w] = (freq[w] || 0) + 1));
return Object.entries(freq)
.sort((a, b) => b[1] - a[1])
.slice(0, 30)
.map(([w, n]) => `${w.padEnd(20)} ${String(n).padStart(5)}`)
.join("\n");
}