Skip to content

Instantly share code, notes, and snippets.

@itzsaga
Created March 7, 2017 04:48
Show Gist options
  • Save itzsaga/5c25c5e107176bdd8e0aec105334395e to your computer and use it in GitHub Desktop.
Save itzsaga/5c25c5e107176bdd8e0aec105334395e to your computer and use it in GitHub Desktop.
# 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