Capitalize Words
JavaScript
easy
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 🔥