File tree 3 files changed +65
-2
lines changed
solution/2100-2199/2129.Capitalize the Title
3 files changed +65
-2
lines changed Original file line number Diff line number Diff line change @@ -133,10 +133,34 @@ func capitalizeTitle(title string) string {
133
133
134
134
### ** TypeScript**
135
135
136
- <!-- 这里可写当前语言的特殊实现逻辑 -->
137
-
138
136
``` ts
137
+ function capitalizeTitle(title : string ): string {
138
+ const ans: string [] = [];
139
+ for (const s of title .split (' ' )) {
140
+ if (s .length < 3 ) {
141
+ ans .push (s .toLowerCase ());
142
+ } else {
143
+ ans .push (
144
+ s .substring (0 , 1 ).toUpperCase () + s .substring (1 ).toLowerCase (),
145
+ );
146
+ }
147
+ }
148
+ return ans .join (' ' );
149
+ }
150
+ ```
139
151
152
+ ``` ts
153
+ function capitalizeTitle(title : string ): string {
154
+ return title
155
+ .split (' ' )
156
+ .map (s =>
157
+ s .length < 3
158
+ ? s .toLowerCase ()
159
+ : s .substring (0 , 1 ).toUpperCase () +
160
+ s .substring (1 ).toLowerCase (),
161
+ )
162
+ .join (' ' );
163
+ }
140
164
```
141
165
142
166
### ** ...**
Original file line number Diff line number Diff line change @@ -121,7 +121,33 @@ func capitalizeTitle(title string) string {
121
121
### ** TypeScript**
122
122
123
123
``` ts
124
+ function capitalizeTitle(title : string ): string {
125
+ const ans: string [] = [];
126
+ for (const s of title .split (' ' )) {
127
+ if (s .length < 3 ) {
128
+ ans .push (s .toLowerCase ());
129
+ } else {
130
+ ans .push (
131
+ s .substring (0 , 1 ).toUpperCase () + s .substring (1 ).toLowerCase (),
132
+ );
133
+ }
134
+ }
135
+ return ans .join (' ' );
136
+ }
137
+ ```
124
138
139
+ ``` ts
140
+ function capitalizeTitle(title : string ): string {
141
+ return title
142
+ .split (' ' )
143
+ .map (s =>
144
+ s .length < 3
145
+ ? s .toLowerCase ()
146
+ : s .substring (0 , 1 ).toUpperCase () +
147
+ s .substring (1 ).toLowerCase (),
148
+ )
149
+ .join (' ' );
150
+ }
125
151
```
126
152
127
153
### ** ...**
Original file line number Diff line number Diff line change
1
+ function capitalizeTitle ( title : string ) : string {
2
+ const ans : string [ ] = [ ] ;
3
+ for ( const s of title . split ( ' ' ) ) {
4
+ if ( s . length < 3 ) {
5
+ ans . push ( s . toLowerCase ( ) ) ;
6
+ } else {
7
+ ans . push (
8
+ s . substring ( 0 , 1 ) . toUpperCase ( ) + s . substring ( 1 ) . toLowerCase ( ) ,
9
+ ) ;
10
+ }
11
+ }
12
+ return ans . join ( ' ' ) ;
13
+ }
You can’t perform that action at this time.
0 commit comments