Created
November 14, 2018 01:30
-
-
Save dannysmith/1e7d5025975dc192c75b1b78bbcceb80 to your computer and use it in GitHub Desktop.
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
| 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