-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
base: master
Are you sure you want to change the base?
Solution #2295
Conversation
There was a problem hiding this 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]; |
There was a problem hiding this comment.
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.
if (toFormat.includes('YY') && fromFormat.includes('YYYY')) { | ||
obj['YY'] = obj['YYYY'].slice(-2); | ||
} |
There was a problem hiding this comment.
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.
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}`; | ||
} | ||
} |
There was a problem hiding this comment.
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.
for (let i = 0; i < toFormat.length - 1; i++) { | ||
newDate.push(obj[toFormat[i]]); | ||
} |
There was a problem hiding this comment.
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]; |
There was a problem hiding this comment.
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.
No description provided.