-
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
done #2211
base: master
Are you sure you want to change the base?
done #2211
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! 🎉 While there are a few minor issues with the premature return statements that could affect the formatting of other date parts, your solution meets the core requirements of the task. Keep up the good work, and consider revising the logic to ensure all parts of the date are formatted before returning. This will make your code even more robust! 😊
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
if (result[index].length === 2) { | ||
return result.join(toFormat[toFormat.length - 1]); | ||
} | ||
|
||
if (result[index].length === 4) { | ||
result[index] = result[index].slice(-2); | ||
|
||
return result.join(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 function returns prematurely if the year is in 'YY' format and is already two digits long. This might not be the intended behavior, as it skips formatting other parts of the date. Consider removing the return statement here and allowing the loop to continue.
if (result[index].length === 4) { | ||
result[index] = result[index].slice(-2); | ||
|
||
return result.join(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.
Similarly, returning here when the year is in 'YYYY' format and is already four digits long may not be correct. Ensure that all parts of the date are formatted before returning.
if (result[index].length === 2) { | ||
if (+result[index] < 30) { | ||
result[index] = 20 + result[index]; | ||
|
||
return result.join(toFormat[toFormat.length - 1]); | ||
} else { | ||
result[index] = 19 + result[index]; | ||
|
||
return result.join(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 logic for converting two-digit years to four-digit years is correct, but returning immediately after updating the year might skip formatting other parts of the date. Consider updating the result
array without returning immediately.
No description provided.