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

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

Solution #2295

wants to merge 1 commit into from

Conversation

RHerheman
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 implementation meets many of the task requirements, there are some critical issues related to how separators are handled in the fromFormat and toFormat arrays. The current logic incorrectly assumes that separators are part of these arrays, which leads to incorrect parsing and formatting of dates. To resolve this, you should handle separators separately from the format arrays. Once these issues are addressed, your solution will be much stronger. Keep up the great work, and don't hesitate to reach out if you need further guidance! 😊

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

@@ -8,7 +8,38 @@
* @returns {string}
*/
function formatDate(date, fromFormat, toFormat) {
// write code here
const separator = fromFormat[fromFormat.length - 1];

Choose a reason for hiding this comment

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

The assumption that the last element of fromFormat is a separator is incorrect. Separators should not be included in the format arrays. You should define separators separately or assume a default one.

Comment on lines +20 to +22
if (toFormat.includes('YY') && fromFormat.includes('YYYY')) {
obj['YY'] = obj['YYYY'].slice(-2);
}

Choose a reason for hiding this comment

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

The logic here assumes that the separator is part of the fromFormat, which is incorrect. The separator should be handled separately from the format array.

Comment on lines +24 to +32
if (toFormat.includes('YYYY') && fromFormat.includes('YY')) {
const yy = Number(obj['YY']);

if (yy < 30) {
obj['YYYY'] = yy === 0 ? `2000` : `20${yy}`;
} else {
obj['YYYY'] = `19${yy}`;
}
}

Choose a reason for hiding this comment

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

Similarly, the logic here assumes that the separator is part of the toFormat, which is incorrect. The separator should be handled separately from the format array.

Comment on lines +36 to +38
for (let i = 0; i < toFormat.length - 1; i++) {
newDate.push(obj[toFormat[i]]);
}

Choose a reason for hiding this comment

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

The loop should iterate over the entire toFormat array, not excluding the last element, as the separator should not be part of the format array.

newDate.push(obj[toFormat[i]]);
}

const newSeparator = 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 assumption that the last element of toFormat is a separator is incorrect. Separators should not be included in the format arrays. You should define separators separately or assume a default one.

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