Skip to content
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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Solution #2159

wants to merge 3 commits into from

Conversation

dmdamyan
Copy link

No description provided.

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a 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;

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;

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;

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;

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;

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);

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;

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;

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.

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a 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 and toFormat 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];

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.

Comment on lines +31 to +32
if (toFormat[0] === 'YYYY' && year.length === 4) {
return year + toFormat[3] + month + toFormat[3] + day;

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.

Comment on lines +35 to +36
if (toFormat[0] === 'YY' && year.length === 4) {
return year.slice(2) + toFormat[3] + month + toFormat[3] + day;

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.

Comment on lines +39 to +40
if (toFormat[0] === 'YY' && year.length === 2) {
return year + toFormat[3] + month + toFormat[3] + day;

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.

Comment on lines +43 to +50
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;

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.

Comment on lines +53 to +54
if (toFormat[2] === 'YYYY' && year.length === 4) {
return day + toFormat[3] + month + toFormat[3] + year;

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.

Comment on lines +57 to +58
if (toFormat[2] === 'YY' && year.length === 4) {
return day + toFormat[3] + month + toFormat[3] + year.slice(2);

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.

Comment on lines +61 to +62
if (toFormat[2] === 'YY' && year.length === 2) {
return day + toFormat[3] + month + toFormat[3] + year;

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.

Comment on lines +65 to +72
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;

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.

Copy link

@volodymyr-soltys97 volodymyr-soltys97 left a 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

Comment on lines 18 to 20
year = dateArray[0];
month = dateArray[1];
day = dateArray[2];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now these values ​​are duplicated in many places, store them in a variable and use the variable everywhere
image

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ПОдскажи как это сделать?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants