char-freq Character frequency analysis
Examples
Analyze character frequencies in a pangram
Usage
"the quick brown fox jumps over the lazy dog" | char-freq Check character distribution in a marketing headline
Usage
"FLASH SALE: 50% OFF ALL ITEMS THIS WEEKEND ONLY!!!" | char-freq Study character frequency in a famous literary quote
Usage
"To be, or not to be, that is the question." | char-freq View source
(input)=>{
const freq = {};
for (const c of input)freq[c] = (freq[c] || 0) + 1;
return Object.entries(freq).sort((a, b)=>b[1] - a[1]).slice(0, 30).map(([c, n])=>{
const display = c === "\n" ? "\\n" : c === "\t" ? "\\t" : c === " " ? "␣" : c;
return `${display.padEnd(4)} ${String(n).padStart(6)} ${"█".repeat(Math.min(40, Math.round((n / input.length) * 200)))}`;
}).join("\n");
}