0
RUBY: Abbreviate a Two Word Name
How do you write a function to convert a name into initials? Strictly speaking, by taking two words, with one space in between them. The Output should be two capital letters with a dot separating them, like this: Sam Harris => S.H Patrick Feeney => P.F So far, I have : 1.) def abbrev_name(name) That’s all 😂 Please help 🙏🏼
2 Réponses
+ 2
def abbrev_name(name)
first, last = name.split(" ")
return "#{first[0]}.#{last[0]}"
end
puts abbrev_name("Sam Harris")
puts abbrev_name("Patrick Feeney")
+ 1
Cheers ChaoticDawg 🖖🏼