-
Notifications
You must be signed in to change notification settings - Fork 68
/
NoYelling.rb
37 lines (30 loc) · 1.09 KB
/
NoYelling.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
33
34
35
36
37
=begin
Write a function taking in a string like WOW this is REALLY amazing and returning
Wow this is really amazing. String should be capitalized and properly spaced.
Using re and string is not allowed.
Examples:
filter_words('HELLO CAN YOU HEAR ME') #=> Hello can you hear me
filter_words('now THIS is REALLY interesting') #=> Now this is really interesting
filter_words('THAT was EXTRAORDINARY!') #=> That was extraordinary!
=end
# My Solution
def filter_words(st)
st.split(" ").join(" ").capitalize
end
=begin
# Codewars random tests
words = ["racecar","madam","kitty","wolf","robert trebor","kata","code wars",
"code edoc","anna","level","radar","sagas","man","woman","internet","website",
"yes","no","this","is","another","word","in","the","random","array","of","word"]
(1..200).each do |rtest|
st = []
(2..rand(50)).each do |x|
temp = words[rand(words.length)] + (" " * rand(1..5))
rand(2) == 1 ? temp = temp.upcase : temp = temp.downcase
st << temp
end
st = st.join
solution = filter_words2(st)
Test.assert_equals(filter_words(st),solution,"Expected: '#{solution}'")
end
=end