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 🙏🏼

15th Nov 2020, 2:03 AM
Ghostglass
Ghostglass - avatar
2 odpowiedzi
+ 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")
15th Nov 2020, 2:26 AM
ChaoticDawg
ChaoticDawg - avatar
+ 1
Cheers ChaoticDawg 🖖🏼
15th Nov 2020, 3:08 AM
Ghostglass
Ghostglass - avatar