-
Notifications
You must be signed in to change notification settings - Fork 68
/
Copy pathQuestion.rb
28 lines (23 loc) · 843 Bytes
/
Question.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
Given a string, write a function that returns the string with a question mark
("?") appends to the end, unless the original string ends with a question mark,
in which case, returns the original string.
ensure_question("Yes") # => "Yes?"
ensure_question("No?") # => "No?"
=end
# My Solution
def ensure_question(s)
s[-1] == "?" ? s : s+"?"
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..5).each do |rtest|
word = words[rand(words.length)]
word = word + "?" if rand(2) == 1
solution = ensure_question2(word)
Test.assert_equals(ensure_question(word),solution,"Expected: '#{solution}'")
end
=end