Problem Brief
Preprocess Dates
INTERNFULLTIMEOA
On a web form, users are asked to enter dates which come in as strings. Before storing them to the database, they need to be converted to a standard safe format. Write a function to convert the dates as described.
Given a date string in the format Day Month Year, where:
- - Day is a string in the form "1st", "2nd", "3rd", "21st", "22nd", "23rd", "31st" and all other are the number + "th", eg: "4th" or "12th".
- - Month is the first three letters of the English language months, like "jan" for January through "Dec" for December.
- - Year is 4 digits ranging from 1900 to 2100.
Convert the date string "Day Month Year" to the date string "YYYY-MM-DD" in the format
"4 digit year - 2 digit month - 2 digit day".
Function Description
Complete the function preprocessDate.
preprocessDate has the following parameter(s):
string dates[n]: an array of date strings in the format Day Month Year
Returns
string[n]: array of converted date strings
1Example 1
Input
dates = ["1st Mar 1974", "22nd Jan 2013", "7th Apr 1904"]
Output
["1974-03-01", "2013-01-22", "1904-04-07"]
Explanation
Constraints
Limits and guarantees your solution can rely on.