Capitalize Words
Write a function that takes a sentence as input and returns a new sentence where the first letter of each word is capitalized, and the rest of the letters are in lowercase.
Input: A string sentence containing one or more words separated by spaces.
Output: A new string where each word starts with an uppercase letter followed by lowercase letters.
Example Inputs & Outputs
// Example 1: Input: "hello world" Output: "Hello World" // Example 2: Input: "javaScript is FUN" Output: "Javascript Is Fun" // Example 3: Input: " multiple spaces " Output: "Multiple Spaces" // Example 4: Input: "" Output: ""
Constraints & Edge Cases
- Input may have multiple spaces between words.
- Input may contain uppercase, lowercase, or mixed-case characters.
- Input can be an empty string.
- Words can contain letters only; punctuation is not considered in this challenge.
- Leading/trailing spaces should be trimmed in the final result.
Solve Similar questions 🔥
Want to upskill? Explore our courses!
Namaste DSA
Master DSA from scratch with numerous problems, and expert guidance.
Namaste React
Wanna dive deep into React and become Frontend Expert? Learn with me now!
Namaste Frontend System Design
The most comprehensive and detailed course for frontend system design.
Namaste Node.js
Wanna dive deep into Node.js? Enroll into `Namaste Node.js` now!
