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 #2185

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

Solution #2185

wants to merge 2 commits into from

Conversation

IvanSierov
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 the formatDate function! While your solution meets many of the task requirements, there are a few critical issues that need to be addressed before we can approve the pull request:

  1. Separator Handling: The current logic assumes that separators are not part of the format strings, which might not hold true for all input cases. It's important to ensure that your function can handle separators correctly, regardless of their position in the format arrays.

  2. Year Conversion Logic: The conversion from 'YY' to 'YYYY' assumes that years less than 30 belong to the 2000s, which might not be accurate for all scenarios. Consider making this logic configurable or implementing a more robust solution to handle different use cases.

  3. Separator Determination: The assumption that the last element of the format arrays is the separator might not always be valid. Please revise this logic to ensure that separators are correctly identified and handled, even if they are not explicitly included as the last element in the format arrays.

Once these issues are addressed, your solution will be much more robust and ready for approval. Keep up the great work, and don't hesitate to reach out if you have any questions! 😊

✨ 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.

Comment on lines 11 to 12
const fromSeparator = fromFormat[fromFormat.length - 1];
const toSeparator = toFormat[toFormat.length - 1];

Choose a reason for hiding this comment

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

The logic for determining the separators assumes that the last element of the format arrays is the separator. This might not be a valid assumption if the format arrays do not include the separator as their last element. Consider revising this logic to handle cases where the separator is not explicitly included in the format arrays.

Comment on lines +30 to +31
if (toFormat.includes('YYYY') && fromFormat.includes('YY')) {
year = year < 30 ? `20${year}` : `19${year}`;

Choose a reason for hiding this comment

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

The logic for converting 'YY' to 'YYYY' assumes that years less than 30 belong to the 2000s and others to the 1900s. This might not be accurate for all use cases. Consider making this logic configurable or providing a more robust solution.

Comment on lines 38 to 48
for (let i = 0; i < toFormat.length - 1; i++) {
if (toFormat[i] === 'YYYY' || toFormat[i] === 'YY') {
newDateParts.push(year);
} else if (toFormat[i] === 'MM') {
newDateParts.push(month);
} else if (toFormat[i] === 'DD') {
newDateParts.push(day);
}
}

return newDateParts.join(toSeparator);

Choose a reason for hiding this comment

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

The loop for constructing the new date parts assumes that the format arrays do not include the separator as part of the format strings. Ensure that this assumption holds true for all input cases or adjust the logic to handle separators 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.

Review Summary

Great effort on implementing the formatDate function! 🎉 While your code is on the right track, there are a few critical issues that need attention:

  1. Separator Handling: The logic for determining separators in fromFormat and toFormat is flawed. The condition arg !== 'YYYY' || arg !== 'YY' || arg !== 'MM' || arg !== 'DD' will always evaluate to true. You should use && instead of || to correctly identify non-date parts. Additionally, ensure that separators are correctly identified and handled, even if they are not explicitly included as the last element in the format arrays.

  2. Year Conversion Logic: The current logic assumes that years less than 30 belong to the 2000s. While this is a common approach, it might not be suitable for all scenarios. Consider making this logic more flexible or configurable to handle different cases.

Despite these issues, the decision is to APPROVE your Pull Request to help you move forward with your learning. Please review the comments and make the necessary improvements to your code. Addressing these critical issues will enhance the functionality and robustness of your solution. 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! ✨

Comment on lines +13 to +16
for (const arg of fromFormat) {
if (arg !== 'YYYY' || arg !== 'YY' || arg !== 'MM' || arg !== 'DD') {
fromSeparator = arg;
}

Choose a reason for hiding this comment

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

The condition arg !== 'YYYY' || arg !== 'YY' || arg !== 'MM' || arg !== 'DD' is incorrect because it will always evaluate to true. This is because arg cannot be equal to all these values at the same time. You should use && instead of || to check if arg is not equal to any of these values.

Comment on lines +35 to +36
if (toFormat.includes('YYYY') && fromFormat.includes('YY')) {
year = year < 30 ? `20${year}` : `19${year}`;

Choose a reason for hiding this comment

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

The logic for converting 'YY' to 'YYYY' assumes that years less than 30 belong to the 2000s. This assumption might not be valid for all scenarios. Consider making this logic configurable or more robust to handle different cases.

Copy link
Author

Choose a reason for hiding this comment

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

This was also stated in the problem statement.
The function can change a separator, reorder the date parts of convert a year from 4 digits to 2 digits and back.

When converting from YYYY to YY just use 2 last digit (1997 -> 97).
When converting from YY to YYYY use 20YY if YY < 30 and 19YY otherwise.

Comment on lines +43 to +53
let toSeparator;

for (let i = 0; i < toFormat.length; i++) {
if (toFormat[i] === 'YYYY' || toFormat[i] === 'YY') {
newDateParts.push(year);
} else if (toFormat[i] === 'MM') {
newDateParts.push(month);
} else if (toFormat[i] === 'DD') {
newDateParts.push(day);
} else {
toSeparator = toFormat[i];

Choose a reason for hiding this comment

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

The logic for determining the toSeparator assumes that the separator is not part of the format strings, which might not always be the case. Ensure that separators are correctly identified and handled, even if they are not explicitly included as the last element in the format arrays.

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.

2 participants