feat(curriculum): restore seed + solution to Chinese (#40683)
* feat(tools): add seed/solution restore script * chore(curriculum): remove empty sections' markers * chore(curriculum): add seed + solution to Chinese * chore: remove old formatter * fix: update getChallenges parse translated challenges separately, without reference to the source * chore(curriculum): add dashedName to English * chore(curriculum): add dashedName to Chinese * refactor: remove unused challenge property 'name' * fix: relax dashedName requirement * fix: stray tag Remove stray `pre` tag from challenge file. Signed-off-by: nhcarrigan <nhcarrigan@gmail.com> Co-authored-by: nhcarrigan <nhcarrigan@gmail.com>
This commit is contained in:
committed by
GitHub
parent
0095583028
commit
ee1e8abd87
@ -3,6 +3,7 @@ id: 5966c21cf732a95f1b67dd28
|
||||
title: 日期操纵
|
||||
challengeType: 5
|
||||
videoUrl: ''
|
||||
dashedName: date-manipulation
|
||||
---
|
||||
|
||||
# --description--
|
||||
@ -69,5 +70,48 @@ assert(
|
||||
);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function add12Hours(dateString) {
|
||||
|
||||
return true;
|
||||
}
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
function add12Hours(dateString) {
|
||||
const months = ['January', 'February', 'March', 'April', 'May', 'June',
|
||||
'July', 'August', 'September', 'October', 'November', 'December'];
|
||||
// Get the parts of the string
|
||||
const parts = dateString.split(' ');
|
||||
const month = months.indexOf(parts[0]);
|
||||
const day = parseInt(parts[1], 10);
|
||||
const year = parseInt(parts[2], 10);
|
||||
const time = parts[3].split(':');
|
||||
let hours = parseInt(time[0], 10);
|
||||
if (time[1].slice(-2) === 'pm') {
|
||||
hours += 12;
|
||||
}
|
||||
const minutes = parseInt(time[1].slice(0, -2), 10);
|
||||
|
||||
// Create a date with given parts, and updated hours
|
||||
const date = new Date();
|
||||
date.setFullYear(year, month, day);
|
||||
date.setHours(hours + 12); // Add 12 hours
|
||||
date.setMinutes(minutes);
|
||||
|
||||
let hoursOutput = date.getHours();
|
||||
let abbreviation = 'am';
|
||||
if (hoursOutput > 12) {
|
||||
hoursOutput -= 12;
|
||||
abbreviation = 'pm';
|
||||
}
|
||||
|
||||
return `${months[date.getMonth()]} ${date.getDate()} ${date.getFullYear()} ${hoursOutput}:${date.getMinutes()}${abbreviation} EST`;
|
||||
}
|
||||
```
|
||||
|
Reference in New Issue
Block a user