-
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 solution #2195
base: master
Are you sure you want to change the base?
add solution #2195
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 task! 😊 While your solution meets many of the task requirements, there are a few critical issues that need to be addressed to ensure the function works correctly and consistently:
-
Direct Modification of
newFormat
: The function currently modifies thenewFormat
array directly. This can lead to unexpected behavior if the same format is reused elsewhere. It's recommended to work with a copy ofnewFormat
to avoid side effects. -
Inconsistent Handling of Date Formats: The logic for handling different date formats ('YY' and 'YYYY') is not consistent. Specifically, the hardcoded century logic for 'YY' might not be flexible for all use cases. Consider making this logic more adaptable.
-
Potential Misalignment of Formats: The function assumes that 'YYYY' is present in both
newFormat
andfromFormat
, but it doesn't handle cases where they might not be aligned correctly. Ensure that the alignment of formats is checked before proceeding with transformations. -
Use of
newArray.pop()
: The use ofnewArray.pop()
to remove the last element may not be necessary or correct for the intended transformation. Verify that this operation aligns with the intended format transformation.
Please address these issues to ensure the function operates as expected. Once these changes are made, your solution will be in great shape! Keep up the great work, and don't hesitate to reach out if you have any questions or need further clarification. 🚀
✨ 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.
if (newFormat.includes('YYYY') && fromFormat.includes('YYYY')) { | ||
for (const n of newFormat) { | ||
const searchInd = fromFormat.indexOf(n); | ||
|
||
newArray.push(array[searchInd]); | ||
} | ||
newArray.pop(); | ||
result = newArray.join(newSeparator); | ||
|
||
return 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 here assumes that both 'YYYY' are present in newFormat
and fromFormat
, but it doesn't handle cases where they might not be aligned correctly. Consider checking the alignment of formats before proceeding.
src/formatDate.js
Outdated
if (newFormat.includes('YY')) { | ||
for (const n of array) { | ||
if (n.length > 3) { | ||
indexYear = array.indexOf(n); | ||
year = n.slice(2); | ||
} | ||
} | ||
array[indexYear] = year; | ||
|
||
const newYY = newFormat.indexOf('YY'); | ||
|
||
newFormat[newYY] = 'YYYY'; | ||
|
||
for (const n of newFormat) { | ||
const searchInd = fromFormat.indexOf(n); | ||
|
||
newArray.push(array[searchInd]); | ||
} | ||
newArray.pop(); | ||
|
||
result = newArray.join(newSeparator); | ||
|
||
return 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.
In this block, the function modifies newFormat
directly by replacing 'YY' with 'YYYY'. This can lead to issues if newFormat
is reused elsewhere. Consider creating a copy of newFormat
before making modifications.
src/formatDate.js
Outdated
if (newFormat.includes('YYYY')) { | ||
indexYearbig = fromFormat.indexOf('YY'); | ||
|
||
if (parseInt(array[indexYearbig]) >= 30) { | ||
yearBig = '19' + array[indexYearbig]; | ||
} | ||
|
||
if (parseInt(array[indexYearbig]) < 30) { | ||
yearBig = '20' + array[indexYearbig]; | ||
} | ||
|
||
array[indexYearbig] = yearBig; | ||
|
||
const newY = newFormat.indexOf('YYYY'); | ||
|
||
newFormat[newY] = 'YY'; | ||
|
||
for (const n of newFormat) { | ||
const searchInd = fromFormat.indexOf(n); | ||
|
||
newArray.push(array[searchInd]); | ||
} | ||
newArray.pop(); | ||
|
||
result = newArray.join(newSeparator); | ||
|
||
return 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.
Similar to the previous block, this section modifies newFormat
directly. It's better to work with a copy to avoid side effects. Additionally, the logic for determining the century based on 'YY' is hardcoded to 30, which might not be flexible for all use cases.
for (const n of newFormat) { | ||
const searchInd = fromFormat.indexOf(n); | ||
|
||
newArray.push(array[searchInd]); |
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 newArray.pop()
operation removes the last element, which might not be necessary or correct depending on the format. Ensure that this operation aligns with the intended format transformation.
|
||
newArray.push(array[searchInd]); | ||
} | ||
newArray.pop(); |
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.
As with the previous comment, ensure that newArray.pop()
is necessary and correct for the intended transformation.
|
||
newArray.push(array[searchInd]); | ||
} | ||
newArray.pop(); |
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.
Again, verify that newArray.pop()
is appropriate for the transformation logic.
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 submission! 🎉 While your formatDate
function has some critical issues that need addressing, such as the direct modification of newFormat
, inconsistent handling of date formats ('YY' and 'YYYY'), potential misalignment of formats, and the unnecessary use of newArray.pop()
, your effort is appreciated. These issues are crucial for the functionality of your code, and I encourage you to review the comments and improve your solution. This approval is to help you move forward with your learning journey. Please ensure to address these issues in future iterations to avoid similar problems. Keep up the good work and continue learning from your experiences! 💪
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
// write code here | ||
let result = ''; | ||
const oldDate = date; | ||
const newFormat = 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.
Directly modifying newFormat
can lead to unexpected behavior if the same format is reused elsewhere. Consider working with a copy of newFormat
to avoid side effects.
|
||
array = oldDate.split(oldSeparator); | ||
|
||
if (newFormat.includes('YYYY') && fromFormat.includes('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.
Ensure that the alignment of formats is checked before proceeding with transformations. The assumption that 'YYYY' is present in both newFormat
and fromFormat
without proper alignment checks can cause errors.
|
||
newArray.push(array[searchInd]); | ||
} | ||
newArray.pop(); |
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 newArray.pop()
to remove the last element may not be necessary or correct for the intended transformation. Verify that this operation aligns with the intended format transformation.
return result; | ||
} | ||
|
||
if (newFormat.includes('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 logic for handling 'YY' is not flexible and might not be suitable for all use cases. Consider making this logic more adaptable.
return result; | ||
} | ||
|
||
if (newFormat.includes('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 handling of 'YYYY' when 'YY' is present in fromFormat
is inconsistent. Ensure that the logic for transforming 'YY' to 'YYYY' is adaptable and consistent.
No description provided.