Last active
January 21, 2018 21:19
-
-
Save RickGriff/32c29932f993ee90cb732b323e0eb647 to your computer and use it in GitHub Desktop.
Codewars Challenge: Stop gninnipS My sdroW!
This file contains hidden or 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
#Write a function that takes in a string of one or more words, and Drop one or more filereturns the same string, but with all | |
#five or more letter words reversed (Just like the name of this Kata). | |
#Strings passed in will consist of only letters and spaces. | |
#Spaces will be included only when more than one word is present. | |
#Examples: | |
#spinWords( "Hey fellow warriors" ) => returns "Hey wollef sroirraw" | |
#spinWords( "This is a test") => returns "This is a test" | |
#spinWords( "This is another test" )=> returns "This is rehtona test" | |
#----- | |
#My Solution | |
def spinWords(string) | |
words = string.split | |
words.map do |word| | |
word.reverse! if word.length >= 5 | |
end | |
words.join(" ") | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment