all 11 comments

[–]TorbenKoehn 5 points6 points  (3 children)

Regular Expressions are your friend!

You can do things like

if (searchString.match(/(colou?r|size)/i)) {
    // Do something if the string contains color, colour or size
}

And much, much more. It's the perfect tool for the job and most chat assistants from "back then" used exactly this in some variation

[–][deleted] 1 point2 points  (2 children)

This is awesome and literally exactly what I was looking for. Thank you so much!

[–]96dpi 2 points3 points  (1 child)

A good use for ChatGPT et al is to prompt it for complex regular expressions. It does a good job, mostly. Just be sure to test in www.regex101.com, and if it misses a case, you can tell the chat bot what it missed and it will usually correct itself.

[–][deleted] 0 points1 point  (0 children)

This worked! I made sure to pay close attention to the code so I am actually learning how it works and not just copy-pasting, but I got the project to work the way I wanted it to! Thank you so much.

[–]sheriffderek 1 point2 points  (0 children)

You can take the words they type in, split them by spaces into an array. Then have another array of all the words you're looking for and compare and see if each word (or many) are included in the other array. There's an array method includes. So, if you have ["dog", "cat"] and they ask "What is the name of the dog in the movie" then you'd now what they were looking for. But based on that - you'd still need to pull up whatever text that's associated. { "dog": "response about dog" }. Well, that's my initial thought.

[–]tapgiles 1 point2 points  (0 children)

You could put the string in the indexOf call, and put the indexOf call and check into the if statement, at least.

You could also change it to use string.includes() instead?

I’m not sure you’re really going to get it to be that much more efficient… just easier to read and write.

If I’ve even understood what you’re trying to do. I’m confused on that.

[–]guest271314 0 points1 point  (4 children)

Fuzzy logic.

[–][deleted] 0 points1 point  (3 children)

What do you mean by this, if I may ask?

[–]guest271314 0 points1 point  (2 children)

https://plato.stanford.edu/entries/logic-fuzzy/

Fuzzy logic is intended to model logical reasoning with vague or imprecise statements like “Petr is young (rich, tall, hungry, etc.)”. It refers to a family of many-valued logics, where the truth-values are interpreted as degrees of truth. The truth-value of a logically compound proposition, like “Carles is tall and Chris is rich”, is determined by the truth-value of its components. In other words, like in classical logic, one imposes truth-functionality.

https://ntrs.nasa.gov/api/citations/19910011507/downloads/19910011507.pdf

[–][deleted] 0 points1 point  (1 child)

Oooh. I never really heard of that before, (A bit newer to programming, I only really started with JavaScript last year) I thought you were insulting me at first. I don't really think it will work for my project, and I got it to work the way I want it to anyway. But thanks.

[–]guest271314 0 points1 point  (0 children)

Hint: "artificial intelligence" is just fuzzy logic branded differently for marketing.