-
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 #2220
base: master
Are you sure you want to change the base?
Solution #2220
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.
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! ✨
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); | ||
} |
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.
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.
if (fromPart1 === 'YY' && toPart1 === 'YYYY') { | ||
if (Number(part1) < 30) { | ||
result = '20' + result; | ||
} | ||
} | ||
|
||
if (fromPart1 === 'YY' && toPart1 === 'YYYY') { | ||
if (part1 >= 30) { | ||
result = '19' + result; | ||
} | ||
} |
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 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); |
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 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.
No description provided.