-
Notifications
You must be signed in to change notification settings - Fork 0
/
reverseArray.rb
32 lines (28 loc) · 930 Bytes
/
reverseArray.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/bin/ruby
# Nairuby Code Challenge - Reverse Array
#
# Given an array:
# ["r", "e", "v", "e", "r", "s", "e", " ", "t", "h", "i", "s", " ", "a", "r", "r", "a", "y"]
#
# Return and print the reverse of that array:
# ["y", "a", "r", "r", "a", " ","s", "i", "h", "t", " ", "e", "s", "r", "e", "v", "e", "r"]
#
# Stipulation: Do not use Array.reverse
#
# BONUS:
# Given the same array, only reverse the 'words' in the array.
#
# ["r", "e", "v", "e", "r", "s", "e", " ", "t", "h", "i", "s", " ", "a", "r", "r", "a", "y"]
#
# Should then return:
# ["a", "r", "r", "a", "y", " ", "t", "h", "i", "s", " ", "r", "e", "v", "e", "r", "s", "e"]
arr = ["r", "e", "v", "e", "r", "s", "e", " ", "t", "h", "i", "s", " ", "a", "r", "r", "a", "y"]
def reverseArray(arr)
# Solution goes in here
end
def reverseWords(arr)
# Solution goes in here
end
printf("%s\n", arr)
printf("%s\n", reverseArray(arr))
printf("%s\n", reverseWords(arr))