0

Why the test case 3 fails?

You and your friends are going to Europe! You have made plans to travel around Europe with your friends, but one thing you need to take into account so that everything goes according to play, is that the format of their date is different than from what is used in the United States. Your job is to convert all your dates from MM/DD/YYYY to DD/MM/YYYY. Task: Create a function that takes in a string containing a date that is in US format, and return a string of the same date converted to EU. Input Format: A string that contains a date formatting 11/19/2019 or November 19, 2019. Output Format: A string of the same date but in a different format: 19/11/2019. Sample Input: 7/26/2019 Sample Output: 26/7/2019 https://code.sololearn.com/ckpl3zH08qKX/?ref=app

18th May 2023, 9:57 PM
Monika Izydorczyk
Monika Izydorczyk - avatar
2 Réponses
+ 1
Well you're getting bad output with single-digit months combined with double-digit days, and based on the output it's an array problem where you're only changing the first of two digits, plus there's no / in that situation for some reason. I'll see if I can help pin it down in the code. edit: yep, it's line 15: date.replace(slash + 1, dayLength, month); slash is still set to the previous location of the "/", so it writes in the wrong place. simple fix: just re-evaluate .find("/") before this replace
19th May 2023, 1:12 AM
Orin Cook
Orin Cook - avatar
0
Thanks a lot. It works now 😀
19th May 2023, 8:58 AM
Monika Izydorczyk
Monika Izydorczyk - avatar