Skip to content

Latest commit

 

History

History
30 lines (26 loc) · 639 Bytes

exclamation_marks_series_№1_remove_an_exclamation_mark_from_the_end_of_string.md

File metadata and controls

30 lines (26 loc) · 639 Bytes

Description

Description

Remove an exclamation mark from the end of a string. For a beginner kata, you can assume that the input data is always a string, no need to verify it.

Examples

"Hi!"     ---> "Hi"
"Hi!!!"   ---> "Hi!!"
"!Hi"     ---> "!Hi"
"!Hi!"    ---> "!Hi"
"Hi! Hi!" ---> "Hi! Hi"
"Hi"      ---> "Hi"

My Solution

def remove(s)
  s[-1] == '!' ? s[0..-2] : s
end

Better/Alternative solution from Codewars

def remove(s)
  s.chomp('!')
end