-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Solution #2159
base: master
Are you sure you want to change the base?
Solution #2159
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your hard work on this task! 😊 While your solution meets many of the task requirements, there's a critical issue with how the separator is handled in the formatDate
function. The code currently assumes that the separator is always at index 3 of the toFormat
array, which may not be accurate for all date formats. This could lead to incorrect date formatting in cases where the separator is located elsewhere.
To improve your solution, please revise the logic to dynamically determine the separator based on the actual format provided. Once this issue is addressed, your code should function correctly across various date formats. Keep up the great work, and I look forward to seeing your updated solution! 🚀
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
🔄 Fix the issues, commit the changes, and then re-request my review using the Re-request review
button in the Reviewers tab.
} | ||
|
||
if (toFormat[0] === 'YYYY' && year.length === 4) { | ||
return year + toFormat[3] + month + toFormat[3] + day; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code assumes that the separator is always at index 3 of the toFormat
array. This assumption may not hold true if the format does not include a separator at that index. Consider revising the logic to dynamically determine the separator based on the format.
} | ||
|
||
if (toFormat[0] === 'YY' && year.length === 4) { | ||
return year.slice(2) + toFormat[3] + month + toFormat[3] + day; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar to the previous comment, the assumption about the separator being at index 3 of the toFormat
array may not be valid. Ensure that the separator is correctly identified based on the format.
} | ||
|
||
if (toFormat[0] === 'YY' && year.length === 2) { | ||
return year + toFormat[3] + month + toFormat[3] + day; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, the assumption about the separator at index 3 of the toFormat
array may not be correct. Adjust the logic to handle different formats appropriately.
year = '20' + year; | ||
} | ||
|
||
return year + toFormat[3] + month + toFormat[3] + day; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The separator is assumed to be at index 3 of the toFormat
array, which may not always be the case. Consider revising the logic to correctly identify the separator.
} | ||
|
||
if (toFormat[2] === 'YYYY' && year.length === 4) { | ||
return day + toFormat[3] + month + toFormat[3] + year; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code assumes the separator is at index 3 of the toFormat
array. This may not be accurate for all formats. Adjust the logic to handle different formats correctly.
} | ||
|
||
if (toFormat[2] === 'YY' && year.length === 4) { | ||
return day + toFormat[3] + month + toFormat[3] + year.slice(2); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The assumption about the separator being at index 3 of the toFormat
array may not be valid. Ensure the separator is correctly identified based on the format.
} | ||
|
||
if (toFormat[2] === 'YY' && year.length === 2) { | ||
return day + toFormat[3] + month + toFormat[3] + year; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The separator is assumed to be at index 3 of the toFormat
array, which may not always be the case. Consider revising the logic to correctly identify the separator.
year = '20' + year; | ||
} | ||
|
||
return day + toFormat[3] + month + toFormat[3] + year; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code assumes the separator is at index 3 of the toFormat
array. This may not be accurate for all formats. Adjust the logic to handle different formats correctly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your submission! 🎉 While your code in the formatDate.js
file demonstrates a good effort, there are some critical issues that need to be addressed to ensure it functions correctly across various date formats.
Key Issues:
- Separator Handling: The current implementation assumes that the separator is always at index 3 of the
fromFormat
andtoFormat
arrays. This is not a reliable method, as the separator can vary and is not guaranteed to be at a fixed index. The logic should be revised to dynamically determine the separator based on the actual format provided.
Moving Forward:
The decision to approve your pull request is made to help you continue progressing in your learning journey. However, it is crucial to address these issues in future iterations to avoid similar problems. Please review the comments and revise your logic to improve your code. Keep up the good work, and continue learning from these experiences! 🚀
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
@@ -8,7 +8,69 @@ | |||
* @returns {string} | |||
*/ | |||
function formatDate(date, fromFormat, toFormat) { | |||
// write code here | |||
const separator = fromFormat[3]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The separator is assumed to be at index 3 of the fromFormat
array, which may not be correct for all date formats. Consider dynamically determining the separator based on the actual format provided.
if (toFormat[0] === 'YYYY' && year.length === 4) { | ||
return year + toFormat[3] + month + toFormat[3] + day; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code assumes the separator is at index 3 of the toFormat
array. This assumption may not hold true for all date formats. Consider revising the logic to dynamically determine the separator.
if (toFormat[0] === 'YY' && year.length === 4) { | ||
return year.slice(2) + toFormat[3] + month + toFormat[3] + day; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The separator is assumed to be at index 3 of the toFormat
array. This assumption may not hold true for all date formats. Consider revising the logic to dynamically determine the separator.
if (toFormat[0] === 'YY' && year.length === 2) { | ||
return year + toFormat[3] + month + toFormat[3] + day; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The separator is assumed to be at index 3 of the toFormat
array. This assumption may not hold true for all date formats. Consider revising the logic to dynamically determine the separator.
if (toFormat[0] === 'YYYY' && year.length === 2) { | ||
if (+year >= 30) { | ||
year = '19' + year; | ||
} else { | ||
year = '20' + year; | ||
} | ||
|
||
return year + toFormat[3] + month + toFormat[3] + day; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The separator is assumed to be at index 3 of the toFormat
array. This assumption may not hold true for all date formats. Consider revising the logic to dynamically determine the separator.
if (toFormat[2] === 'YYYY' && year.length === 4) { | ||
return day + toFormat[3] + month + toFormat[3] + year; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The separator is assumed to be at index 3 of the toFormat
array. This assumption may not hold true for all date formats. Consider revising the logic to dynamically determine the separator.
if (toFormat[2] === 'YY' && year.length === 4) { | ||
return day + toFormat[3] + month + toFormat[3] + year.slice(2); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The separator is assumed to be at index 3 of the toFormat
array. This assumption may not hold true for all date formats. Consider revising the logic to dynamically determine the separator.
if (toFormat[2] === 'YY' && year.length === 2) { | ||
return day + toFormat[3] + month + toFormat[3] + year; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The separator is assumed to be at index 3 of the toFormat
array. This assumption may not hold true for all date formats. Consider revising the logic to dynamically determine the separator.
if (toFormat[2] === 'YYYY' && year.length === 2) { | ||
if (+year >= 30) { | ||
year = '19' + year; | ||
} else { | ||
year = '20' + year; | ||
} | ||
|
||
return day + toFormat[3] + month + toFormat[3] + year; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The separator is assumed to be at index 3 of the toFormat
array. This assumption may not hold true for all date formats. Consider revising the logic to dynamically determine the separator.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job 👍
Let's improve your code
src/formatDate.js
Outdated
year = dateArray[0]; | ||
month = dateArray[1]; | ||
day = dateArray[2]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ПОдскажи как это сделать?
No description provided.