I want to make a basic AI chat in Javascript.
1) If a user says 'Hi, my name is Thore' I want to check what the closest match is with some predefined values.
My array looks like this:
const nameSentences = [`my name is`, `i'm`, `they call me`];
How can I check what the closest match is? In this example it should be the first value of my array.
2) The second part is how I can get the name out of the user input. Is it possible to predefine a place where the variable should stand?
Something like this
const nameSentences = [`my name is ${varName}`, `i'm ${varName}`, `they call me ${varName}`];
And afterwards substring the matching sentence with the user input to save the name the variable?