I’m working on a side project that is essentially a word search. What I want to do is when a user selects and submits a word the program needs to check that this is a valid english word. I could use advice on the best way to accomplish this.
I’ve considered using a word list like this: https://github.com/marcoagpinto/aoo-mozilla-en-dict/tree/master/en_US%20(Kevin%20Atkinson) And having my program use a loop to search for a match between user input and the list. Issue that I see is that I’m not sure how efficient this would be. Additionally I’d have to somehow format the list as an array to search through and I’m not sure how to do that.
Are you planning on using a back end for this project?
I was intending this to be a front end only project as I’ve only just completed that section… Unless it’s not possible?
Let’s say I go with a static dictionary built with a word list, such as the example I posted above. Would the best approach be to break the words down into 26 arrays based on their first letter. I could test the first letter of my user input then use a for loop for the corresponding array to see if there is a match. Or is this silly? Up until now my loops haven’t had to process this much information so I’m not sure the best way to approach this.
That would make sense to me. Also keep in mind that the dictionary will come in alphabetical order and that can be taken advantage of. You could implement something called a ‘binary search’ which is a pretty fast finding algorithm. The EdX CS50 course covers this concept in good detail.
words.indexOf(word) !== -1
edit: I still feel like loading so much data into your static files is probably not the best idea. This API looks promising:
This looks like an excellent api for the job! Thanks for sharing!