Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sockets - Erica & Karla G. #7

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open

Conversation

kguadron
Copy link

Adagrams

Congratulations! You're submitting your assignment.

Comprehension Questions

Feature Feedback
What are the components that make up a method? A method is made up of the method signature and the method block.
What are the advantages of using git when collaboratively working on one code base? The advantage is that it's easy to see what other collaborators are doing and share/merge changes.
What kind of relationship did you and your pair have with the unit tests? It was helpful for debugging and seeing where in the code the errors were coming up.
Does your code use any methods from the Enumerable mixin? If so, where and why was it helpful? We used .each and .each_char. It was helpful in iterating through the individual elements in the different arrays.
What was one method you and your pair used to debug code? We used the unit tests and puts statements.
What are two discussion points that you and your pair discussed when giving/receiving feedback from each other that you would be willing to share? 1) We have different coding paces and acknowledged that it's important to strike a balance. 2) We fostered a safe/comfortable working dynamic where we were able to communicate needs, ideas, and points of confusion.

@droberts-sea
Copy link

Adagrams

What We're Looking For

Feature Feedback
General
Answered comprehension questions yes
Small commits with meaningful commit messages yes - good work!
Code Requirements
draw_letters method
Uses appropriate data structure to store the letter distribution see inline
All tests for draw_letters pass yes
uses_available_letters? method
All tests for uses_available_letters? pass yes
score_word method
Uses appropriate data structure to store the letter scores see inline
All tests for score_word pass yes
highest_score_from method
Appropriately handles edge cases for tie-breaking logic yes
All tests for highest_score_from pass yes
Overall

Good job overall. There are a few places where things could be cleaned up, which I've tried to call out below, but in general I am happy with what I see here. It's clear to me that the learning goals around working with methods and tests were met. Keep up the hard work!

def draw_letters
available_letters = {"a" => 9, "b" => 2, "c" => 2, "d" => 4, "e" => 12, "f" => 2, "g" => 3, "h" => 2,
"i" => 9, "j" => 1, "k" => 1, "l" => 4, "m" => 2, "n" => 6, "o" => 8, "p" => 2,
"q" => 1, "r" => 6, "s" => 4, "t" => 6, "u" => 4, "v" => 2, "w" => 2, "x" => 1,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love this data structure - it makes it very clear how many there are of each letter. Could you store it in a constant?

10.times do
letter = available_letters.keys.sample
while available_letters[letter] == 0
letter = available_letters.keys.sample

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By this logic, you're as likely to draw an e as you are a z!

Instead, you might create an array containing all the letters, with code similar to this:

letter_counts = {
  # the hash you had before
}
letters = []
letter_counts.each do |letter, count|
  count.times do
    letters << letter
  end
end

Then you could pull a random tile with letters.sample and get a nice even distribution.

class Array
def delete_elements_in_(array)
array.each do |x|
if index = index(x)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Be careful about this sort of monkey patching - it's typically considered bad form. Instead, you could write a helper method that's not part of the Array class:

def delete_from(hay, needles)
  needles.each do |needle|
    if index = hay.index(needle)
      hay.delete_at(index)
    end
  end
end

input.each_char do |letter|
if letters_in_hand.include?(letter) == true
letters_in_hand.delete_elements_in_([letter])
used_letters << letter

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you only use delete_elements_in_ with an array of length 1, it might make sense to make the argument be a single object instead of an array.

Please make sure you fully understand the code you borrow from other sources before including it in your project.

when "a", "e", "i", "o", "u", "l", "n", "r", "s", "t"
score += 1
when "d", "g"
score += 2

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While this case statement works, it means that the information about which letter has which score is locked into this piece of code, and can't easily be used elsewhere. For example, if you wanted to display the value of each letter in a hand, you would need to repeat this work.

An alternative approach would be to store the letter scores in a hash, something like this:

LETTER_SCORES = {
  "A" => 1
  "B" => 3,
  "C" => 3,
  "D" => 2,
  # ...
}

Then to get the score for a letter, you can say LETTER_SCORES[letter].

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants