-
Notifications
You must be signed in to change notification settings - Fork 0
/
mexican_wave.rb
28 lines (26 loc) · 802 Bytes
/
mexican_wave.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
=begin Mexican Wave
Create a function that turns a string into a Mexican Wave. You will be passed
a string and you must return that string in an array where an uppercase letter
is a person standing up.
Always will be a lowercase but empty.
If the character in the string is whitespace then pass over it as if it were
an empty seat
Examples:
"hello" => "Hello" "hEllo" "heLlo" "helLo" "hellO"
"two words" =>
=end
def wave(input)
mexican_wave = []
last_index_on_string = input.length - 1
string = input
0.upto(last_index_on_string) do |n|
if input[n] != " "
string[n] = string[n].upcase
variable = string.clone # Ruby is a pass by memory reference
mexican_wave.push(variable)
string[n] = string[n].downcase
end
end
puts mexican_wave
end
wave("hellogoodbye")