2021-06-15 00:49:18 -07:00
|
|
|
---
|
|
|
|
id: 59669d08d75b60482359409f
|
2022-02-04 00:46:32 +05:30
|
|
|
title: Formato della data
|
2021-06-15 00:49:18 -07:00
|
|
|
challengeType: 5
|
|
|
|
forumTopicId: 302243
|
|
|
|
dashedName: date-format
|
|
|
|
---
|
|
|
|
|
|
|
|
# --description--
|
|
|
|
|
2022-02-04 00:46:32 +05:30
|
|
|
Restituisci un array con due stringhe data della data corrente con le seguenti specificazioni:
|
2021-06-15 00:49:18 -07:00
|
|
|
|
2022-02-04 00:46:32 +05:30
|
|
|
- L'ordine della prima stringa dovrebbe essere numero dell'anno, numero del mese, e numero del giorno separati da trattini (`-`).
|
|
|
|
- L'anno della prima stringa dovrebbe avere una lunghezza di quattro cifre.
|
|
|
|
- Il mese e il giorno della prima stringa non dovrebbero avere degli zeri all'inizio.
|
|
|
|
- Il giorno della settimana e del mese nella seconda stringa dovrebbero essere in inglese e non dovrebbero essere abbreviat.
|
|
|
|
- Il giorno della seconda stringa non dovrebbe avere alcuno zero all'inizio.
|
2021-06-15 00:49:18 -07:00
|
|
|
|
2022-02-04 00:46:32 +05:30
|
|
|
Esempi di output:
|
2021-06-15 00:49:18 -07:00
|
|
|
|
|
|
|
```js
|
|
|
|
['2007-11-23', 'Friday, November 23, 2007']
|
|
|
|
['2021-3-2', 'Tuesday, March 2, 2021']
|
|
|
|
```
|
|
|
|
|
|
|
|
# --hints--
|
|
|
|
|
2022-02-04 00:46:32 +05:30
|
|
|
`getDateFormats` dovrebbe essere una funzione.
|
2021-06-15 00:49:18 -07:00
|
|
|
|
|
|
|
```js
|
|
|
|
assert(typeof getDateFormats === 'function');
|
|
|
|
```
|
|
|
|
|
2022-02-04 00:46:32 +05:30
|
|
|
`getDateFormats` dovrebbe restituire un oggetto.
|
2021-06-15 00:49:18 -07:00
|
|
|
|
|
|
|
```js
|
|
|
|
assert(typeof getDateFormats() === 'object');
|
|
|
|
```
|
|
|
|
|
2022-02-04 00:46:32 +05:30
|
|
|
`getDateFormats` dovrebbe restituire un array con 2 elementi.
|
2021-06-15 00:49:18 -07:00
|
|
|
|
|
|
|
```js
|
|
|
|
assert(getDateFormats().length === 2);
|
|
|
|
```
|
|
|
|
|
2022-02-04 00:46:32 +05:30
|
|
|
`getDateFormats` dovrebbe restituire la data corretta nel formato giusto
|
2021-06-15 00:49:18 -07:00
|
|
|
|
|
|
|
```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];
|
|
|
|
}
|
|
|
|
```
|