RUBY: Abbreviate a Two Word Name | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
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 Respostas
+ 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