Markov Chains

I am discovering N8N little by little and I gave myself a challenge that was a little too difficult for me.
Indeed, I want to make a script allowing from a sentence to generate a Markov chain.
Do you have any ideas for building the script?

I found some resources here is the link: Using Markov Chains in JavaScript - Gregorio Martinez

Thank you in advance for your advice and help on the subject.