Skip to content

Commit 8927c8d

Browse files
committed
feat: add ts solution to lc problem: No.1507
1 parent 20f7188 commit 8927c8d

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

solution/1500-1599/1507.Reformat Date/README.md

+14
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,20 @@ class Solution {
143143
}
144144
```
145145

146+
### **TypeScript**
147+
148+
```ts
149+
function reformatDate(date: string): string {
150+
const s = date.split(' ');
151+
const months = ' JanFebMarAprMayJunJulAugSepOctNovDec';
152+
const day = parseInt(s[0].substring(0, s[0].length - 2));
153+
const month = Math.floor(months.indexOf(s[1]) / 3) + 1;
154+
return `${s[2]}-${month.toString().padStart(2, '0')}-${day
155+
.toString()
156+
.padStart(2, '0')}`;
157+
}
158+
```
159+
146160
### **...**
147161

148162
```

solution/1500-1599/1507.Reformat Date/README_EN.md

+14
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,20 @@ class Solution {
130130
}
131131
```
132132

133+
### **TypeScript**
134+
135+
```ts
136+
function reformatDate(date: string): string {
137+
const s = date.split(' ');
138+
const months = ' JanFebMarAprMayJunJulAugSepOctNovDec';
139+
const day = parseInt(s[0].substring(0, s[0].length - 2));
140+
const month = Math.floor(months.indexOf(s[1]) / 3) + 1;
141+
return `${s[2]}-${month.toString().padStart(2, '0')}-${day
142+
.toString()
143+
.padStart(2, '0')}`;
144+
}
145+
```
146+
133147
### **...**
134148

135149
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
function reformatDate(date: string): string {
2+
const s = date.split(' ');
3+
const months = ' JanFebMarAprMayJunJulAugSepOctNovDec';
4+
const day = parseInt(s[0].substring(0, s[0].length - 2));
5+
const month = Math.floor(months.indexOf(s[1]) / 3) + 1;
6+
return `${s[2]}-${month.toString().padStart(2, '0')}-${day
7+
.toString()
8+
.padStart(2, '0')}`;
9+
}

0 commit comments

Comments
 (0)