pipr.tools

word-freq

Word frequency analysis

# Stats

Try it

stdin0 chars
stdout0 chars

Example

Find most frequent words in a sentence

Usage
$ echo "the cat sat on the mat and the cat purred" | word-freq
View source
(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");
    }

Suggested Pipelines

Related Tools