1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import { markovChoice } from "https://esm.town/v/jdan/markovChoice";
export function traversePairwise(chain) {
let node = "START";
let result = [];
while (node !== "END") {
node = markovChoice(chain[node]);
result.push(node);
}
// 1. Trim END off the end
// 2. Take the entire two-character string if it's the first iteration
// 3. Take only the last character otherwise
return result.slice(0, -1).map((word, idx) => {
if (idx === 0) {
return word;
}
return word[word.length - 1];
});
}