Skip to content

Instantly share code, notes, and snippets.

@dannysmith
Created November 14, 2018 01:30
Show Gist options
  • Select an option

  • Save dannysmith/1e7d5025975dc192c75b1b78bbcceb80 to your computer and use it in GitHub Desktop.

Select an option

Save dannysmith/1e7d5025975dc192c75b1b78bbcceb80 to your computer and use it in GitHub Desktop.
def reverse_alternate(string)
words = string.split(' ')
words.each_with_index { |word, i| word.reverse! if i.odd? }
return words.join(' ')
end
reverse_alternate('one two three four') #=> 'one owt three ruof'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment