forked from AdaGold/portmanteau-generator
-
Notifications
You must be signed in to change notification settings - Fork 50
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 - Shirley #30
Open
shirley1chu
wants to merge
2
commits into
Ada-C11:master
Choose a base branch
from
shirley1chu:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
def is_vowel?(letter) | ||
return ["a", "e", "i", "o", "u"].include?(letter) | ||
end | ||
|
||
def length_validation(word) | ||
until word.length >= 2 && word.count("aeiou") > 0 | ||
puts "Please enter a word greater than one character long that also has at least one vowel" | ||
word = gets.chomp | ||
end | ||
return word | ||
end | ||
|
||
# method to find the index of desired vowel, whether it be first or last vowel | ||
# char_idx represents index for the letter that you want to start iterating at | ||
def find_vowel_index(word, char_idx, count_direction) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like that you broke this out into it's own method |
||
vowel_index = char_idx | ||
word.length.times do | ||
if is_vowel?(word[char_idx]) | ||
vowel_index = char_idx | ||
break | ||
end | ||
char_idx += count_direction | ||
end | ||
return vowel_index | ||
end | ||
|
||
def run_generator | ||
puts "What is the first word to combine?" | ||
first_word = length_validation(gets.chomp) | ||
puts "What is the second word to combine?" | ||
second_word = length_validation(gets.chomp) | ||
puts "The first word is #{first_word}. The second word is #{second_word} in the run_generator method" | ||
first_word_last_vowel = find_vowel_index(first_word, -1, -1) | ||
# addresses special case that the last letter in the first word is a consonant, since it should not be chopped off | ||
if first_word_last_vowel == -1 && is_vowel?(first_word[-1]) == false | ||
first_portion = first_word | ||
else | ||
first_portion = first_word[0...first_word_last_vowel] | ||
end | ||
second_word_first_vowel = find_vowel_index(second_word, 0, 1) | ||
second_portion = second_word[second_word_first_vowel..-1] | ||
puts "Portmanteau: #{first_portion}" + "#{second_portion}" | ||
end | ||
|
||
run_generator | ||
|
||
puts "\nWould you like to continue the generator? Please enter yes to continue, or enter anything else to exit" | ||
while gets.chomp.downcase == "yes" | ||
run_generator | ||
puts "\nWould you like to continue the generator? Please enter yes to continue, or enter anything else to exit" | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You miss upper case characters here! one way to fix this is using
letter.downcase()