Skip to content

Instantly share code, notes, and snippets.

@jalcine
Last active August 29, 2015 14:13
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 jalcine/a3614f9e30f584d93961 to your computer and use it in GitHub Desktop.
Save jalcine/a3614f9e30f584d93961 to your computer and use it in GitHub Desktop.
# Reverse letters in string.
def reverse_abstract(list)
max_distance = (list.length - 1 / 2)
for i in 0..max_distance do
left_index = i
right_index = list.length - i - 1
left_entry = list[left_index]
right_entry = list[right_index]
list[left_index] = right_entry
list[right_index] = left_entry
end
list
end
def reverse(str)
reverse_abstract(flipped_str)
end
def reverse_words(sentence)
words = sentence.split ' '
new_words = reverse_abstract(sentence)
new_words.join ' '
end
puts reverse('hello')
puts reverse_words('Welcome to the magical world of Iron Man.')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment