Practice

Problem 1 of 12

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

  1. Task 1, not checked yet. Make tidyName pass the example tests.

  2. Task 2, not checked yet. Make tidyName pass the hidden tests.

Task 1 of 2

Make tidyName pass the example tests.

All tasks

main.js

Ctrl+Enter runs your code. Ctrl+Shift+Enter runs all the tests. Press Esc, then Tab, to leave the editor.

Output

Press Run to see your result

Your output shows here. Press Run to try your code.