* 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>
86 lines
2.0 KiB
Markdown
86 lines
2.0 KiB
Markdown
---
|
|
id: 59669d08d75b60482359409f
|
|
title: 日期格式
|
|
challengeType: 5
|
|
videoUrl: ''
|
|
dashedName: date-format
|
|
---
|
|
|
|
# --description--
|
|
|
|
任务:
|
|
|
|
返回包含以下格式的当前日期的数组:
|
|
|
|
\- 2007-11-23和
|
|
|
|
\- 2007年11月23日星期日
|
|
|
|
示例输出: `['2007-11-23', 'Sunday, November 23, 2007']`
|
|
|
|
# --hints--
|
|
|
|
`getDateFormats`是一个函数。
|
|
|
|
```js
|
|
assert(typeof getDateFormats === 'function');
|
|
```
|
|
|
|
应该返回一个对象。
|
|
|
|
```js
|
|
assert(typeof getDateFormats() === 'object');
|
|
```
|
|
|
|
应该返回一个包含2个元素的数组。
|
|
|
|
```js
|
|
assert(getDateFormats().length === 2);
|
|
```
|
|
|
|
应以正确的格式返回正确的日期
|
|
|
|
```js
|
|
assert.deepEqual(getDateFormats(), dates, equalsMessage);
|
|
```
|
|
|
|
# --seed--
|
|
|
|
## --after-user-code--
|
|
|
|
```js
|
|
const getDateSolution = () => {
|
|
const date = new Date();
|
|
const weekdays = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
|
|
const months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
|
|
const fmt1 = `${date.getFullYear()}-${(1 + date.getMonth())}-${date.getDate()}`;
|
|
const fmt2 = `${weekdays[date.getDay()]}, ${months[date.getMonth()]} ${date.getDate()}, ${date.getFullYear()}`;
|
|
return [fmt1, fmt2];
|
|
};
|
|
|
|
const dates = getDateSolution();
|
|
const equalsMessage = `message: <code>getDataFormats()</code> should return <code>["${dates[0]}", "${dates[1]}"]</code>.`;
|
|
```
|
|
|
|
## --seed-contents--
|
|
|
|
```js
|
|
function getDateFormats() {
|
|
|
|
return true;
|
|
}
|
|
```
|
|
|
|
# --solutions--
|
|
|
|
```js
|
|
function getDateFormats() {
|
|
const date = new Date();
|
|
const weekdays = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
|
|
const months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
|
|
const fmt1 = `${date.getFullYear()}-${(1 + date.getMonth())}-${date.getDate()}`;
|
|
const fmt2 = `${weekdays[date.getDay()]}, ${months[date.getMonth()]} ${date.getDate()}, ${date.getFullYear()}`;
|
|
return [fmt1, fmt2];
|
|
}
|
|
```
|