File tree 3 files changed +31
-0
lines changed
solution/1400-1499/1451.Rearrange Words in a Sentence
3 files changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -162,6 +162,18 @@ class Solution {
162
162
}
163
163
```
164
164
165
+ ### ** TypeScript**
166
+
167
+ ``` ts
168
+ function arrangeWords(text : string ): string {
169
+ let words: string [] = text .split (" " );
170
+ words [0 ] = words [0 ].toLowerCase ();
171
+ words .sort ((a , b ) => a .length - b .length );
172
+ words [0 ] = words [0 ].charAt (0 ).toUpperCase () + words [0 ].slice (1 );
173
+ return words .join (" " );
174
+ }
175
+ ```
176
+
165
177
### ** ...**
166
178
167
179
```
Original file line number Diff line number Diff line change @@ -147,6 +147,18 @@ class Solution {
147
147
}
148
148
```
149
149
150
+ ### ** TypeScript**
151
+
152
+ ``` ts
153
+ function arrangeWords(text : string ): string {
154
+ let words: string [] = text .split (" " );
155
+ words [0 ] = words [0 ].toLowerCase ();
156
+ words .sort ((a , b ) => a .length - b .length );
157
+ words [0 ] = words [0 ].charAt (0 ).toUpperCase () + words [0 ].slice (1 );
158
+ return words .join (" " );
159
+ }
160
+ ```
161
+
150
162
### ** ...**
151
163
152
164
```
Original file line number Diff line number Diff line change
1
+ function arrangeWords ( text : string ) : string {
2
+ let words : string [ ] = text . split ( " " ) ;
3
+ words [ 0 ] = words [ 0 ] . toLowerCase ( ) ;
4
+ words . sort ( ( a , b ) => a . length - b . length ) ;
5
+ words [ 0 ] = words [ 0 ] . charAt ( 0 ) . toUpperCase ( ) + words [ 0 ] . slice ( 1 ) ;
6
+ return words . join ( " " ) ;
7
+ }
You can’t perform that action at this time.
0 commit comments