Created
March 7, 2017 04:48
-
-
Save itzsaga/5c25c5e107176bdd8e0aec105334395e to your computer and use it in GitHub Desktop.
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
# FIRST METHOD THAT PASSED | |
def reverse_each_word(array) | |
new_array = array.split(" ") | |
reversed_array = new_array.each {|x| x.reverse!} | |
return reversed_array.join(" ") | |
end | |
# FIRST REFACTORED CODE | |
def reverse_each_word(array) | |
new_array = array.split(" ") | |
new_array.collect {|x| x.reverse!} | |
new_array.join(" ") | |
end | |
# FINAL SOLUTION | |
def reverse_each_word(array) | |
array.split(" ").collect {|x| x.reverse!}.join(" ") | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment