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 - Cyndi #32

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Sockets - Cyndi #32

wants to merge 1 commit into from

Conversation

cyndilopez
Copy link

@cyndilopez cyndilopez commented Feb 8, 2019

Portmanteau Generator

Congratulations! You're submitting your assignment.

Comprehension Questions

Question Answer
What went well in your code style, such as indentation, spacing, variable names, readability, etc.? What was lacking? The indentation and readability are okay. The variable names I chose could have been better.
How did creating the is_vowel? method affect your project? The is_vowel method made my code more readable. It was called multiple times in multiple methods to determine whether a vowel was encountered.
What was your strategy for getting the correct set of letters from the first word into the portmanteau? First, I reversed the characters in the word. Then I iterated through the characters in the first word and added a number to a count variable until a vowel was encountered. The count variable is the index. I did simple arithmetic to find the index of the vowel for the original word (not reversed) and used this number to extract a substring of the first word using the built-in method splice.
What was your strategy for validating against inputs under 2 characters? I used an if-else statement to check the length of the input. If the length was less than 2, the user was prompted to enter a different word.
In the next project, what would you change about your process? What would you keep doing? I would write a pseudo-code and try different methods for finding the index of a vowel. I would keep trying to
make the code shorter by avoiding repeating lines of code through methods.

@cyndilopez cyndilopez closed this Feb 8, 2019
@droberts-sea droberts-sea reopened this Feb 19, 2019
@droberts-sea
Copy link

Portmanteau Generator

What We're Looking For

Feature Feedback
Readable code with consistent indentation yes
Practices using variables appropriately mostly, but see inline
Practices using conditionals appropriately yes
Practices iteration appropriately yes
Practices using custom methods appropriately yes
Program validates against input under 2 characters yes
Takes in two inputs and creates a portmanteau yes

Good job overall! I really like the way you experimented with breaking different functionality out into different methods. There were a few places where I saw room for improvement, which I've tried to call out inline below, but in general I am happy with this submission. Keep up the hard work!

when "a", "e", "i", "o", "u"
return "true"
else
return "false"

Choose a reason for hiding this comment

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

You should return true or false (the boolean value) here, rather than "true" or "false" (a string containing the word "true" or "false"). Getting comfortable with using different data types is an important thing to practice early on.

def rev_str(strg)
aa = strg.split("")
rev = Array.new
aa.length.times do

Choose a reason for hiding this comment

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

Could you use more specific variable names here?

  • rev_str could be reverse_string
  • aa could be string_array
  • rev could be reversed

IMO, that would make this code much easier to read.

Choose a reason for hiding this comment

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

Also, Ruby has a way to do this built in: String#reverse

puts "abcd".reverse
# => dcba

puts "What is the second word to combine?"
b = gets.chomp.downcase
b = check_length(b)
b = check_contain_vowel(b)

Choose a reason for hiding this comment

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

I love the idea of breaking these individual tasks out into separate methods - that makes the flow of this code very easy to understand. Good work!

If you wanted to go even further, you could combine these 4 repeated lines into another method, maybe something like get_user_input.

if word.length < 2
until word.length > 1
puts "Your word must be 2 or more characters."
word = gets.chomp

Choose a reason for hiding this comment

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

I think this method would do exactly the same thing if you removed the if statement entirely:

def check_length(word)
  until word.length > 1
    puts "Your word must be 2 or more characters."
    word = gets.chomp
  end
  return word
end

def vowel_index(word)
count = 0
word.each_char { |letter|
if is_vowel(letter) == "false"

Choose a reason for hiding this comment

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

In general, I would prefer you use do..end over {..}. It makes the code a little easier to read.

def check_contain_vowel(word)
count = vowel_index(word)
if count == word.length
until count != word.length

Choose a reason for hiding this comment

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

Again, you don't need both the if and the until, since they're checking the same thing. If count != word.length, the until loop won't run at all.

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.

2 participants