Experimenting with Markov Code
https://thecodingtrain.com/challenges/42-markov-chain-name-generator
I made a for loop to loop over text n-grams of length order
for (var i = 0; i <= txt.length - order; i++) {
var gram = txt.substring(i, i + order);
if (!ngrams[gram]) {
ngrams[gram] = [];
}
ngrams[gram].push(txt.charAt(i + order));
}
Each gram is added to each ngram as a key
Result of adjusted code so far:
I needed to adjust markovIt to specify a different starting point so the recipes would have more variety. I also increased the maximum length so the recipe wouldn’t get cut off.
I then came across the issue of it cutting off the start of sentences, also it was just so random and wasn’t really what I had in mind. I increased the order nnumber to see if that would help with the structure of the sentences more.
I also added this to improve readability using line breaks: