Skip to content

Instantly share code, notes, and snippets.

@RickGriff
Last active January 21, 2018 21:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RickGriff/32c29932f993ee90cb732b323e0eb647 to your computer and use it in GitHub Desktop.
Save RickGriff/32c29932f993ee90cb732b323e0eb647 to your computer and use it in GitHub Desktop.
Codewars Challenge: Stop gninnipS My sdroW!
#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