-
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
add task solution #2172
base: master
Are you sure you want to change the base?
add task solution #2172
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 this pull request! 😊 While your solution meets many of the task requirements, there are a few critical issues that need to be addressed to ensure the formatDate
function works correctly:
-
Delimiter Handling: The use of
newDeleteLastElement
as a delimiter for joining date parts may not align with the expected format intoFormat
. Ensure that the delimiter matches the intended output format. -
Year Conversion Logic: The conversion from 'YY' to 'YYYY' relies on a hardcoded threshold ('30'), which might not be suitable for all scenarios. Consider making this logic more flexible or configurable to accommodate different use cases.
-
Handling 'YYYY' in
fromFormat
: The current logic assumes 'YYYY' is always present infromFormat
, which might not be true. Ensure your code can handle cases where 'YYYY' is absent. -
Correct Population of
partOfDate
: ThepartOfDate
array is not correctly populated. Make sure it accurately reflects the segments of the date string based onfromFormatCopy
. -
Date String Splitting: The method for splitting the date string using
deleteLastElement
is flawed. This approach assumes the last element offromFormat
is a delimiter, which may not always be the case. Consider a more robust parsing method.
Please address these issues to ensure the function performs as expected. Keep up the great work, and don't hesitate to reach out if you need further clarification or assistance! 🚀
✨ 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.
src/formatDate.js
Outdated
const deleteLastElement = fromFormatCopy.pop(); | ||
const partOfDate = date.split(deleteLastElement); |
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 splitting the date string using deleteLastElement
is incorrect. This assumes that the last element of fromFormat
is a delimiter, which may not always be the case. Consider using a more robust method to parse the date string based on the format provided.
src/formatDate.js
Outdated
const partsOfDate = {}; | ||
|
||
fromFormatCopy.forEach((part, index) => { | ||
partsOfDate[part] = partOfDate[index]; |
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 partOfDate
array is not correctly populated. Since partOfDate
is derived from splitting the date string, ensure that it contains the correct segments corresponding to fromFormatCopy
. Otherwise, partsOfDate
will not be populated correctly.
src/formatDate.js
Outdated
if (toFormatCopy.includes('YY') && partsOfDate['YYYY']) { | ||
partsOfDate['YY'] = partsOfDate['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 conversion from 'YYYY' to 'YY' assumes that 'YYYY' is always present, which might not be the case. Ensure that the logic handles cases where 'YYYY' is not provided in fromFormat
.
src/formatDate.js
Outdated
if (toFormatCopy.includes('YYYY') && partsOfDate['YY']) { | ||
partsOfDate['YYYY'] = | ||
partsOfDate['YY'] < '30' | ||
? '20' + partsOfDate['YY'] | ||
: '19' + partsOfDate['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.
The conversion from 'YY' to 'YYYY' is based on a hardcoded threshold ('30'), which might not be suitable for all use cases. Consider making this logic more flexible or configurable.
src/formatDate.js
Outdated
const newDeleteLastElement = toFormatCopy.pop(); | ||
const newDate = toFormatCopy | ||
.map((part) => partsOfDate[part]) | ||
.join(newDeleteLastElement); |
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 issue with fromFormat
, using newDeleteLastElement
as a delimiter for joining the date parts may not be correct. Ensure that the delimiter used matches the expected format in toFormat
.
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.
Review Summary
Great job on implementing the formatDate
function! 🎉 Your code meets the task requirements, and it's clear you've put in a lot of effort. However, there are a few critical issues that need attention to ensure the function works flawlessly:
-
Delimiter Handling: The use of
newSeparator
for joining date parts may not align with the expected format intoFormat
. Ensure that the delimiter matches the intended output format. -
Year Conversion Logic: The conversion logic from 'YY' to 'YYYY' uses a hardcoded threshold ('30'), which might not be suitable for all scenarios. Consider making this logic more flexible or configurable.
-
Handling 'YYYY' in
fromFormat
: The logic assumes that 'YYYY' is always present infromFormat
, which might not be true. Ensure that the code can handle cases where 'YYYY' is absent. -
Date String Splitting: The logic assumes that the last element of
fromFormat
is a separator, which may not always be the case. Consider using a more robust method to determine the separator.
These issues should be addressed in future iterations to avoid similar problems. Keep up the great work, and use this feedback to refine your skills further. Remember, learning from mistakes is a crucial part of the development process. 😊
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
const separator = fromFormatCopy.pop(); | ||
const parts = date.split(separator); |
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 assumes that the last element of fromFormat
is a separator, which may not always be the case. This could lead to incorrect splitting of the date string. Consider using a more robust method to determine the separator.
if (toFormatCopy.includes('YY') && dateParts['YYYY']) { | ||
dateParts['YY'] = dateParts['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 'YYYY' is always present in fromFormat
, which might not be true. Ensure that the code can handle cases where 'YYYY' is absent.
if (toFormatCopy.includes('YYYY') && dateParts['YY']) { | ||
dateParts['YYYY'] = | ||
dateParts['YY'] < '30' ? '20' + dateParts['YY'] : '19' + dateParts['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.
The conversion logic from 'YY' to 'YYYY' uses a hardcoded threshold ('30'), which might not be suitable for all scenarios. Consider making this logic more flexible or configurable.
const newSeparator = toFormatCopy.pop(); | ||
|
||
const newDate = toFormatCopy | ||
.map((part) => dateParts[part]) | ||
.join(newSeparator); |
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 use of newSeparator
as a delimiter for joining date parts may not align with the expected format in toFormat
. Ensure that the delimiter matches the intended output format.
No description provided.