Published
Edited
Apr 16, 2022
Importers
2 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
function check({target}) {
target.style.backgroundColor = seen.has(target.innerText) ? 'lightgreen' : 'lightblue';
}
Insert cell
Insert cell
snap = new Set(`
a am and are at
because
can
do
for
go
has have he here
I in is it
like little look
me my
no not
of
play
said see she
the this to
up
was we what where with
yes you
`.trim().split(/\s+/))
Insert cell
Insert cell
highFrequency = new Set(`
as
be but
from
on
say
that they
`.trim().split(/\s+/))
Insert cell
all = shuffle, d3.shuffle([...new Set([...snap, ...highFrequency])])
Insert cell
<style>
@import url('https://fonts.googleapis.com/css2?family=Architects+Daughter&display=swap');

.grid {
display: grid;
grid-template-columns: repeat(${Math.floor(width / 175)}, 1fr);
grid-gap: 5px;
}
.grid button {
padding: 1em;
background-color: whitesmoke;
border: solid 1px hsla(0, 0%, 90%, .3);
border-radius: 3px;
color: black;
font: bold 30px 'Architects Daughter';
}
</style>
Insert cell
Insert cell
seen = new Set(`
a am and are
can
do
for
go
has have he here
I is it
like little look
my
no
play
said see she
the this to
was we what where
yes you
`.trim().split(/\s+/))
Insert cell
upcoming = [...snap].filter((d) => !seen.has(d))
Insert cell
Insert cell
dictionary = (await FileAttachment("oed.txt").text()).trim().split("\n")
Insert cell
Insert cell
suffixes = {
const trie = new Map();
for (const word of dictionary) {
let node = trie;
for (const letter of Array.from(word).reverse()) {
if (!node.has(letter)) node.set(letter, new Map());
node = node.get(letter);
}
node.set(".", word);
}
return trie;
}
Insert cell
Insert cell
function* families(min, node = suffixes) {
if (!(node instanceof Map)) return;
const leaves = d3.filter(node.values(), (m) => m instanceof Map && m.has("."));
if (leaves.length >= min) yield leaves.map((m) => m.get("."));
for (const descendant of node.values()) yield* families(min, descendant);
}
Insert cell
[...families(5)].filter((d) => d[0].length === 4).reverse()
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more