File tree 2 files changed +23
-0
lines changed
2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change
1
+ /**
2
+ * 2129. Capitalize the Title
3
+ * https://leetcode.com/problems/capitalize-the-title/
4
+ * Difficulty: Easy
5
+ *
6
+ * You are given a string title consisting of one or more words separated by a single space,
7
+ * where each word consists of English letters. Capitalize the string by changing the
8
+ * capitalization of each word such that:
9
+ * - If the length of the word is 1 or 2 letters, change all letters to lowercase.
10
+ * - Otherwise, change the first letter to uppercase and the remaining letters to lowercase.
11
+ * Return the capitalized title.
12
+ */
13
+
14
+ /**
15
+ * @param {string } title
16
+ * @return {string }
17
+ */
18
+ var capitalizeTitle = function ( title ) {
19
+ return title . split ( / \s + / ) . map ( word => {
20
+ return word . toLowerCase ( ) . replace ( / ^ \w / , l => word . length > 2 ? l . toUpperCase ( ) : l ) ;
21
+ } ) . join ( ' ' ) ;
22
+ } ;
Original file line number Diff line number Diff line change 279
279
2095|[ Delete the Middle Node of a Linked List] ( ./2095-delete-the-middle-node-of-a-linked-list.js ) |Medium|
280
280
2099|[ Find Subsequence of Length K With the Largest Sum] ( ./2099-find-subsequence-of-length-k-with-the-largest-sum.js ) |Medium|
281
281
2114|[ Maximum Number of Words Found in Sentences] ( ./2114-maximum-number-of-words-found-in-sentences.js ) |Easy|
282
+ 2129|[ Capitalize the Title] ( ./2129-capitalize-the-title.js ) |Easy|
282
283
283
284
## License
284
285
You can’t perform that action at this time.
0 commit comments