Clean your codebase with basic information theory
Cut out everything that’s not surprising.
– Derek Sivers
Surprise
The following equation measures
“surprise”:
It’s easy to estimate the surprise of text files:
const rx = /[\s,\]\[\(\)]+/g;
const counts = {};
for (const file of Deno.args)
for (const x of (await Deno.readTextFile(file)).split(rx))
counts[x] = 1 + counts[x] || 1;
const total = Object.values(counts).reduce((a, b) => a + b, 0);
let entropy = 0;
for (const c of Object.values(counts)) {
const p = c / total;
entropy -= p * Math.log2(p)...
Read more at taylor.town