Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 9ebcd48

Browse files
authored
feat: add js solution to lc problem: No.1451 (#1024)
1 parent 730384f commit 9ebcd48

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

‎solution/1400-1499/1451.Rearrange Words in a Sentence/README.md‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,22 @@ function arrangeWords(text: string): string {
174174
}
175175
```
176176

177+
### **JavaScript**
178+
179+
```js
180+
/**
181+
* @param {string} text
182+
* @return {string}
183+
*/
184+
var arrangeWords = function (text) {
185+
let arr = text.split(' ');
186+
arr[0] = arr[0].toLocaleLowerCase();
187+
arr.sort((a, b) => a.length - b.length);
188+
arr[0] = arr[0][0].toLocaleUpperCase() + arr[0].substr(1);
189+
return arr.join(' ');
190+
};
191+
```
192+
177193
### **...**
178194

179195
```

‎solution/1400-1499/1451.Rearrange Words in a Sentence/README_EN.md‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,22 @@ function arrangeWords(text: string): string {
159159
}
160160
```
161161

162+
### **JavaScript**
163+
164+
```js
165+
/**
166+
* @param {string} text
167+
* @return {string}
168+
*/
169+
var arrangeWords = function (text) {
170+
let arr = text.split(' ');
171+
arr[0] = arr[0].toLocaleLowerCase();
172+
arr.sort((a, b) => a.length - b.length);
173+
arr[0] = arr[0][0].toLocaleUpperCase() + arr[0].substr(1);
174+
return arr.join(' ');
175+
};
176+
```
177+
162178
### **...**
163179

164180
```
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/**
2+
* @param {string} text
3+
* @return {string}
4+
*/
5+
var arrangeWords = function (text) {
6+
let arr = text.split(' ');
7+
arr[0] = arr[0].toLocaleLowerCase();
8+
arr.sort((a, b) => a.length - b.length);
9+
arr[0] = arr[0][0].toLocaleUpperCase() + arr[0].substr(1);
10+
return arr.join(' ');
11+
};

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /