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

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

Solution #2220

wants to merge 1 commit into from

Conversation

NadiiaBulmak
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 a few areas for improvement, such as optimizing the initial assignment of result and refining the logic for year conversion, these are minor and do not impact the core functionality. Keep up the good work, and consider these suggestions for future enhancements! 😊

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

Comment on lines +25 to +34
if (fromPart3 === 'YYYY' && toPart3 === 'YY') {
newPart = part3.slice(-2);

result = [part1, part2, newPart].join(separatorTo);
}

if (fromPart3 === 'YYYY' && toPart3 === 'YY') {
newPart = part3.slice(-2);
result = [part1, part2, newPart].join(separatorTo);
}

Choose a reason for hiding this comment

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

There are duplicate conditions for converting 'YYYY' to 'YY'. Lines 25-29 and 31-34 perform the same operation. You should remove one of these duplicate blocks to avoid redundancy.

Comment on lines +36 to +46
if (fromPart1 === 'YY' && toPart1 === 'YYYY') {
if (Number(part1) < 30) {
result = '20' + result;
}
}

if (fromPart1 === 'YY' && toPart1 === 'YYYY') {
if (part1 >= 30) {
result = '19' + result;
}
}

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' is flawed. The current implementation incorrectly appends '20' or '19' to the entire result string, which could lead to incorrect formatting. You should prepend '20' or '19' only to the part1 and then reconstruct the date.

const [fromPart1, fromPart2, fromPart3, separatorFrom] = fromFormat; //
const [toPart1, toPart2, toPart3, separatorTo] = toFormat; //
const [part1, part2, part3] = date.split(separatorFrom);
let result = date.split(separatorFrom).join(separatorTo);

Choose a reason for hiding this comment

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

The initial assignment of result is not effectively utilized. The logic for formatting the date should be based on the conditions, and this initial assignment may lead to incorrect results if not properly updated.

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