String Formatter

Normalize names with string cleanup and formatting functions.

Start building, submit solution and get feedback from the community.
2Submit Solution
5 upvotes10 upvotes

String Formatter

A signup form is receiving names with inconsistent spacing and casing. Normalize the names before showing them back to the user.

Write these functions:

  • cleanText(text) should remove spaces from the start and end of a string.

  • capitalize(text) should uppercase the first character and lowercase the rest.

  • formatDisplayName(firstName, lastName) should clean and capitalize both names, then return the full display name.

Sample checks:

js
console.log(formatDisplayName('  ava', 'STONE  '));console.log(formatDisplayName('nOAh', '  kim'));console.log(formatDisplayName('  mINA  ', 'pATEL'));

Expected output:

txt
Ava StoneNoah KimMina Patel

formatDisplayName should reuse the smaller helpers instead of repeating all the string cleanup work.

Join the Community

roadmap.sh is the most starred project on GitHub and is visited by hundreds of thousands of developers every month.

Rank  out of 28M!

361K

GitHub Stars

Star us on GitHub
Help us reach #1

+90k every month

+2.1M

Registered Users

Register yourself
Commit to your growth

+2k every month

49K

Discord Members

Join on Discord
Join the community

Roadmaps Best Practices Guides Videos FAQs YouTube

roadmap.sh by @kamrify

Community created roadmaps, best practices, projects, articles, resources and journeys to help you choose your path and grow in your career.

ThewNewStack

The top DevOps resource for Kubernetes, cloud-native computing, and large-scale development and deployment.