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

task solution #2173

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

task solution #2173

wants to merge 1 commit into from

Conversation

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

Great job on implementing the formatDate function! 🎉 Your solution meets the task requirements and handles the conversion of date formats effectively. While there are some assumptions in the code regarding separators and format indices, these do not impact the core functionality. Keep up the good work, and consider refining these areas for even more robust code in the future! 😊

✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨

Comment on lines +11 to +12
const splitSeparator = fromFormat[fromFormat.length - 1];
const splitDate = date.split(splitSeparator);

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 last element of fromFormat is the separator, which may not always be the case. Consider explicitly specifying the separator or handling cases where the separator is not the last element.

const splitSeparator = fromFormat[fromFormat.length - 1];
const splitDate = date.split(splitSeparator);

const joinSeparator = toFormat[toFormat.length - 1];

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 code assumes that the last element of toFormat is the separator. Ensure that this assumption holds true for all inputs or adjust the logic to handle different cases.

Comment on lines +17 to +19
const fromYYYY = fromFormat.includes('YY')
? fromFormat.indexOf('YY')
: fromFormat.indexOf('YYYY');

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 index of the year format (YY or YYYY) is correct, but ensure that fromFormat always contains one of these formats to avoid potential errors.

Comment on lines +24 to +26
const toYYYY = toFormat.includes('YY')
? toFormat.indexOf('YY')
: toFormat.indexOf('YYYY');

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 index of the year format in toFormat is correct, but similar to the previous comment, ensure that toFormat always contains one of these formats to avoid potential errors.

Comment on lines +30 to +32
if (fromFormat[fromYYYY].length > toFormat[toYYYY].length) {
splitDate[fromYYYY] = splitDate[fromYYYY].slice(2);
}

Choose a reason for hiding this comment

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

This block correctly handles the conversion from a four-digit year to a two-digit year. Ensure that the input year is always valid to prevent slicing errors.

Comment on lines +34 to +40
if (fromFormat[fromYYYY].length < toFormat[toYYYY].length) {
if (+splitDate[fromYYYY] < 30) {
splitDate[fromYYYY] = '20' + splitDate[fromYYYY];
} else {
splitDate[fromYYYY] = '19' + splitDate[fromYYYY];
}
}

Choose a reason for hiding this comment

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

This block handles the conversion from a two-digit year to a four-digit year based on a threshold. Ensure that the threshold logic (year < 30) is appropriate for all use cases.

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