-
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
task solution #2173
base: master
Are you sure you want to change the base?
task solution #2173
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 some assumptions in the code regarding separators and format indices, these do not impact the core functionality. Keep up the good work, and consider refining these areas for even more robust code in the future! 😊
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
const splitSeparator = fromFormat[fromFormat.length - 1]; | ||
const splitDate = date.split(splitSeparator); |
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 code assumes that the last element of fromFormat
is the separator, which may not always be the case. Consider explicitly specifying the separator or handling cases where the separator is not the last element.
const splitSeparator = fromFormat[fromFormat.length - 1]; | ||
const splitDate = date.split(splitSeparator); | ||
|
||
const joinSeparator = 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.
Similar to the previous comment, the code assumes that the last element of toFormat
is the separator. Ensure that this assumption holds true for all inputs or adjust the logic to handle different cases.
const fromYYYY = fromFormat.includes('YY') | ||
? fromFormat.indexOf('YY') | ||
: fromFormat.indexOf('YYYY'); |
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 determining the index of the year format (YY
or YYYY
) is correct, but ensure that fromFormat
always contains one of these formats to avoid potential errors.
const toYYYY = toFormat.includes('YY') | ||
? toFormat.indexOf('YY') | ||
: toFormat.indexOf('YYYY'); |
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 determining the index of the year format in toFormat
is correct, but similar to the previous comment, ensure that toFormat
always contains one of these formats to avoid potential errors.
if (fromFormat[fromYYYY].length > toFormat[toYYYY].length) { | ||
splitDate[fromYYYY] = splitDate[fromYYYY].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.
This block correctly handles the conversion from a four-digit year to a two-digit year. Ensure that the input year is always valid to prevent slicing errors.
if (fromFormat[fromYYYY].length < toFormat[toYYYY].length) { | ||
if (+splitDate[fromYYYY] < 30) { | ||
splitDate[fromYYYY] = '20' + splitDate[fromYYYY]; | ||
} else { | ||
splitDate[fromYYYY] = '19' + splitDate[fromYYYY]; | ||
} | ||
} |
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.
This block handles the conversion from a two-digit year to a four-digit year based on a threshold. Ensure that the threshold logic (year < 30) is appropriate for all use cases.
No description provided.