Chapter 18 of 22Part IV: Data, Media & Machine Intelligence
Finding a Needle in a Digital Universe
4 Verified Book Snippets
Every .js file below is byte-identical (SHA-256 verified) to the printed code in Volume 1. Runnable blocks execute inside an isolated sandboxed iframe and Web Worker with a 2-second timeout and zero network access.
Printed book snippet (byte-identical) · 388 bytes · SHA-256: 63d90befac31…
Standalone runnable
Dependencies: None (standard ES2022 JavaScript). Defines pure JavaScript functions/data; runs cleanly in the sandbox (add a console.log call in your own test to inspect return values).
function words(text) {
return text.toLowerCase()
.match(/[a-z0-9]+/g) || [];
}
function makeIndex(docs) {
const index = new Map();
for (const doc of docs) {
const terms = new Set(
words(doc.title + " " + doc.text));
for (const word of terms) {
if (!index.has(word))
index.set(word, []);
index.get(word).push(doc.id);
}
}
return index;
}