Ports - Elise & Faiza#11
Conversation
AdagramsWhat We're Looking For
Great work on this project, you two! It's very obvious that you two took the time to refactor and find the most elegant solution to the problem. In some ways, I think that this could lead to confusion because you two did very advanced syntax, but in some other ways, I think that it created a beautiful, elegant solution. Overall, you have some interesting, logical, concise code! Also, nice work on the optional wave! Especially with adding tests! Last note... Why was there a change from |
| end | ||
| } | ||
|
|
||
| return letters.sample(10) |
There was a problem hiding this comment.
Clever! Nicely done to use the optional argument of sample to get exactly what you need in one line.
|
|
||
| def score_word(word) | ||
| word = word.upcase | ||
| score = (word.length >= 7) ? 8 : 0 |
| {:letters => ["K"], :score => 5}, | ||
| {:letters => ["J", "X"], :score => 8}, | ||
| {:letters => ["Q", "Z"], :score => 10}, | ||
| ] |
There was a problem hiding this comment.
Very interesting and cool data structure! It helps give a relationship between the letters and the score, while keeping it flexible in case letters need to move around. It feels a little more difficult to read compared to a just a hash (rather than your array of hashes), but this is still a great solution
There was a problem hiding this comment.
Hi Dee! Thank you for the feedback. I agree with you it is better to save the letter/score pairs in a hash. I wanted to save some keystrokes. Would something like this work?
hash = {}
%w("a", "b", "c"). each { |letter| hash[letter] = 1 }
%w("q", "z"). each { |letter| hash[letter] = 10 }
Or is there a better way?
There was a problem hiding this comment.
I think that's a great, more readable solution! I like it :)
| next | ||
| end | ||
| end | ||
| return {:word => candidate, :score => max_score} |
There was a problem hiding this comment.
I really like this hash that was made in-line inside of the return! :)
| def is_in_english_dict?(input) | ||
| # instant look up using set | ||
| dictionary = Set.new | ||
| CSV.foreach("/Users/elisepham/Ada/adagrams/assets/dictionary-english.csv", headers: true) do |row| |
There was a problem hiding this comment.
You put in a path to Elise's file on Elise's computer... which doesn't work on every laptop! You should change it to the relative path ./assets/dictionary-english.csv in order for this to work on every machine that uses rake to run the tests
| expect(is_in_english_dict?(element)).must_equal false | ||
| end | ||
| end | ||
| end |
There was a problem hiding this comment.
Great work on writing tests for your new features :)
Adagrams
Congratulations! You're submitting your assignment.
Comprehension Questions
Enumerablemixin? If so, where and why was it helpful?include?method to check if the word is in the dictionary. It was helpful because it returns a boolean value to let us know if the word is present in the dictionary.