Kata Countdown word game
We set ourselves a kata as part of out monthly meeting at work, to create a countdown word game from the UK gameshow. We could use any language we liked. The front end guys used javascript and the back end guys used go and some used php.
Here is my approach
My idea was to get the list for letters and compare them against the words in the json. If the words contained the letters return the words. Then if the words only contained the letters, I knew these would be the words I needed. Then save the key for these so I could then return the words later. That was the idea anyway. After lots of research I decided to use underscore.js as it had this nice function intersection. The docs says “Computes the list of values that are the intersection of all the arrays. Each value in the result is present in each of the arrays.” So this was exactly what I wanted.
- Get a word list to use to compare. npm word list
- Access the word list and create a list of letters to use (add this into input later)
- Using a for loop, loop over the objects and get the keys and the values.
- Save the values to a variable.
- Get the length of the values.
- Using the intersection function compare my letters against the list of words.
- If the length of the of the word with the matching items is the same length as a word in the dictionary it must be a full word, and this is what i want to return.
- Find the key of the matching words.
- Return the key reference which is the matching words.
Improvements:
Currently this method wont compare double letters :-(