-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Pig Latin - End of My Rope! - [\"a\"] #10
Comments
not sure but it looks like you're interpolating an array: "#{split_array_letter}" where split_array_letter is an array will make a string containing You can look for others' solutions here: https://github.com/ultrasaurus/test-first-teaching/tree/master/learn_ruby/pig_latin/solution On Thu, May 16, 2013 at 11:08 AM, ianalexh [email protected] wrote:
Alex Chaffee - [email protected] |
Yes, that's it! Replace With ...and it works. And I can see why. NOW I can look at others' solutions! Had to figure it out on my own first.... I'm sure in six months or a year I'll be looking at my own solutions and LAUGHING - same way I laugh at the way I used to use Photoshop when I first started. Thanks so much!
|
https://github.com/alexch/learn_ruby/tree/master/04_pig_latin
All right, 6-8 hours over 3 days on this one.... could use a clue...
I feel I'm very close. The idea is to split the string into words, and then split the words into letters. Find the first vowel in each letter array - with a special case if inculde?("q")
repl.it appears to give me the correct return, but rspec does not.
Example from rspec:
expected: "appleay"
got: "["a", "p", "p", "l", "e"][]ay" (using ==)
Any easy way to turn "a", "p"\ into "ap"? array.join and array.flatten don't do it.
My code - which I'm pretty proud of after all this time:
def translate(string)
string.downcase!
split_array = string.split(" ")
split_array_final_composite = []
split_array_letter_end = []
split_array.each do |word|
if word.include?("q")
#here I'm trying to get an index for the first vowel. Has to be a better way, but it works!
string_copy = word.clone
string_copy[/[aeio]/] = ''
string_index = string_copy.index("")
split_array_letter = word.split("")
split_array_letter_end = split_array_letter.shift(string_index)
split_array_final_composite<<"#{split_array_letter}#{split_array_letter_end}ay"
end
split_array_final_composite.flatten #this is un-necessary
return split_array_final_composite.join(" ")
end
translate("the quick red fox jumps over the lazy dog")
repl.it returns:
=> "ethay ickquay edray oxfay umpsjay overay ethay azylay ogday"
** It just now occurs to me that perhaps I don't have to split into letters any more, since now I've found a different way to find that vowel index, which was the original purpose of splitting into letters..... I'll try again without that step and see what happens.....
** No, that's right, I did need to split into letters because "shift" works for entire array elements, not for each contstituent part of the element.... still stumped....
The text was updated successfully, but these errors were encountered: