dde272c4b8
i18n - Build Validation / Validate i18n Builds (24) (push) Has been cancelled
CI - Node.js / Lint (24) (push) Has been cancelled
CI - Node.js / Build (24) (push) Has been cancelled
CI - Node.js / Test (24) (push) Has been cancelled
CI - Node.js / Test - Upcoming Changes (24) (push) Has been cancelled
CI - Node.js / Test - i18n (italian, 24) (push) Has been cancelled
CI - Node.js / Test - i18n (portuguese, 24) (push) Has been cancelled
CD - Docker - GHCR Images / Build and Push Images (push) Has been cancelled
1.8 KiB
1.8 KiB
id, title, challengeType, dashedName
| id | title | challengeType | dashedName |
|---|---|---|---|
| 69162d64f96574d9bb629f03 | Challenge 118: Date Formatter | 28 | challenge-118 |
--description--
Given a date in the format "Month day, year", return the date in the format "YYYY-MM-DD".
- The given month will be the full English month name. For example:
"January","February", etc. - In the return value, pad the month and day with leading zeros if necessary to ensure two digits.
For example, given "December 6, 2025", return "2025-12-06".
--hints--
formatDate("December 6, 2025") should return "2025-12-06".
assert.equal(formatDate("December 6, 2025"), "2025-12-06");
formatDate("January 1, 2000") should return "2000-01-01".
assert.equal(formatDate("January 1, 2000"), "2000-01-01");
formatDate("November 11, 1111") should return "1111-11-11".
assert.equal(formatDate("November 11, 1111"), "1111-11-11");
formatDate("September 7, 512") should return "512-09-07".
assert.equal(formatDate("September 7, 512"), "512-09-07");
formatDate("May 4, 1950") should return "1950-05-04".
assert.equal(formatDate("May 4, 1950"), "1950-05-04");
formatDate("February 29, 1992") should return "1992-02-29".
assert.equal(formatDate("February 29, 1992"), "1992-02-29");
--seed--
--seed-contents--
function formatDate(dateString) {
return dateString;
}
--solutions--
function formatDate(dateString) {
const months = {
January: "01",
February: "02",
March: "03",
April: "04",
May: "05",
June: "06",
July: "07",
August: "08",
September: "09",
October: "10",
November: "11",
December: "12"
};
const [month, day, year] = dateString.replace(",", "").split(" ");
return `${year}-${months[month]}-${day.padStart(2, "0")}`;
}