Problem · Easy · 10 min
Tidy a name
- Easy
- Strings
People type names in many ways, for example " aDA loVElace ". A form should save every name in one fixed way.
Write tidyName(name). It takes a string and returns the tidy version:
- Remove the spaces at the start and at the end.
- Replace each run of spaces inside the name with one space.
- Write the first letter of each word in upper case, and the other letters in lower case.
The input holds only letters and spaces. It can be empty. For an empty input, return "".
Examples
| Call | Result |
|---|---|
tidyName(' aDA loVElace ') |
'Ada Lovelace' |
tidyName('grace hopper') |
'Grace Hopper' |
tidyName('') |
'' |
Tasks
2 to do
Task 1, not checked yet. Make
tidyNamepass the example tests.Task 2, not checked yet. Make
tidyNamepass the hidden tests.
Task 1 of 2
Make tidyName pass the example tests.