2018-09-30 22:01:58 +00:00
|
|
|
---
|
|
|
|
id: 59669d08d75b60482359409f
|
2020-11-27 18:02:05 +00:00
|
|
|
title: Date format
|
2018-09-30 22:01:58 +00:00
|
|
|
challengeType: 5
|
2019-08-05 16:17:33 +00:00
|
|
|
forumTopicId: 302243
|
2021-01-13 02:31:00 +00:00
|
|
|
dashedName: date-format
|
2018-09-30 22:01:58 +00:00
|
|
|
---
|
|
|
|
|
2020-11-27 18:02:05 +00:00
|
|
|
# --description--
|
|
|
|
|
2021-03-02 23:46:30 +00:00
|
|
|
Return an array with two date strings of the current date with the following specifications:
|
2020-11-27 18:02:05 +00:00
|
|
|
|
2021-03-02 23:46:30 +00:00
|
|
|
- The first string's date order should be the year number, month number, and day number separated by dashes (`-`).
|
|
|
|
- The first string's year should be four digits in length.
|
|
|
|
- The first string's month and day should not contain any leading zeros.
|
|
|
|
- The second string's weekday and month names should not be abbreviated.
|
|
|
|
- The second string's day should not contain any leading zeros.
|
2018-09-30 22:01:58 +00:00
|
|
|
|
2021-03-02 23:46:30 +00:00
|
|
|
Example outputs:
|
|
|
|
|
|
|
|
```js
|
|
|
|
['2007-11-23', 'Friday, November 23, 2007']
|
|
|
|
['2021-3-2', 'Tuesday, March 2, 2021']
|
|
|
|
```
|
2018-09-30 22:01:58 +00:00
|
|
|
|
2020-11-27 18:02:05 +00:00
|
|
|
# --hints--
|
2018-09-30 22:01:58 +00:00
|
|
|
|
2020-11-27 18:02:05 +00:00
|
|
|
`getDateFormats` should be a function.
|
2018-09-30 22:01:58 +00:00
|
|
|
|
2020-11-27 18:02:05 +00:00
|
|
|
```js
|
|
|
|
assert(typeof getDateFormats === 'function');
|
2018-09-30 22:01:58 +00:00
|
|
|
```
|
|
|
|
|
2020-11-27 18:02:05 +00:00
|
|
|
`getDateFormats` should return an object.
|
2018-09-30 22:01:58 +00:00
|
|
|
|
2020-11-27 18:02:05 +00:00
|
|
|
```js
|
|
|
|
assert(typeof getDateFormats() === 'object');
|
|
|
|
```
|
2018-09-30 22:01:58 +00:00
|
|
|
|
2020-11-27 18:02:05 +00:00
|
|
|
`getDateFormats` should return an array with 2 elements.
|
2018-09-30 22:01:58 +00:00
|
|
|
|
|
|
|
```js
|
2020-11-27 18:02:05 +00:00
|
|
|
assert(getDateFormats().length === 2);
|
2018-09-30 22:01:58 +00:00
|
|
|
```
|
|
|
|
|
2020-11-27 18:02:05 +00:00
|
|
|
`getDateFormats` should return the correct date in the right format
|
|
|
|
|
|
|
|
```js
|
|
|
|
assert.deepEqual(getDateFormats(), dates, equalsMessage);
|
|
|
|
```
|
2018-09-30 22:01:58 +00:00
|
|
|
|
2020-11-27 18:02:05 +00:00
|
|
|
# --seed--
|
2018-09-30 22:01:58 +00:00
|
|
|
|
2020-11-27 18:02:05 +00:00
|
|
|
## --after-user-code--
|
2018-09-30 22:01:58 +00:00
|
|
|
|
|
|
|
```js
|
2018-10-20 18:02:47 +00:00
|
|
|
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>.`;
|
2018-09-30 22:01:58 +00:00
|
|
|
```
|
|
|
|
|
2020-11-27 18:02:05 +00:00
|
|
|
## --seed-contents--
|
2018-09-30 22:01:58 +00:00
|
|
|
|
2020-11-27 18:02:05 +00:00
|
|
|
```js
|
|
|
|
function getDateFormats() {
|
2018-09-30 22:01:58 +00:00
|
|
|
|
2020-11-27 18:02:05 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
```
|
2018-09-30 22:01:58 +00:00
|
|
|
|
2020-11-27 18:02:05 +00:00
|
|
|
# --solutions--
|
2018-09-30 22:01:58 +00:00
|
|
|
|
|
|
|
```js
|
2019-02-26 08:07:07 +00:00
|
|
|
function getDateFormats() {
|
2018-09-30 22:01:58 +00:00
|
|
|
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];
|
|
|
|
}
|
|
|
|
```
|