Your challenge is to take a name (string) as input, like
Albert Einstein
and output:
Einstein, Albert
Pseudocode:
set in to input
set arr to in split by " "
set last to the last element of arr
remove the last element of arr
set out to arr joined with " "
prepend ", " to out
prepend last to out
output out
More test cases:
John Fitzgerald Kennedy => Kennedy, John Fitzgerald
Abraham Lincoln => Lincoln, Abraham
Rules
- The input will always match the regex
^([A-Z][a-z]+ )+([A-Z][a-z]+)$
. - You don't need to handle weird names, even if the output is technically incorrect it is fine here.
- Trailing whitespace / newline is OK.
- Any questions? Comment below!
le
with,
and you have this question \$\endgroup\$le
with,
. \$\endgroup\$