-
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 #2197
base: master
Are you sure you want to change the base?
solution #2197
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 to meet the task requirements! 🎉 While there are some minor issues with the use of splice
instead of split
, your solution effectively handles the conversion of date formats, including changing separators and reordering date parts. Keep up the good work, and consider refining the string handling for even better code quality in the future. 😊
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
function formatDate(date, fromFormat, toFormat) { | ||
// write code here | ||
const separator = fromFormat.splice(3, 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 splice
method is used incorrectly here. splice
is an array method, but fromFormat
is expected to be an array of strings. You should use split
to separate the format string into components if needed.
function formatDate(date, fromFormat, toFormat) { | ||
// write code here | ||
const separator = fromFormat.splice(3, 1); | ||
const newSeparator = toFormat.splice(3, 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 line, splice
is incorrectly used here. Use split
to handle string separation.
if (fromFormat.includes('YY') && toFormat.includes('YYYY')) { | ||
if (dateSplit[fromFormat.indexOf('YY')] < 30) { | ||
result[i] = `20${dateSplit[fromFormat.indexOf('YY')]}`; | ||
} else { | ||
result[i] = `19${dateSplit[fromFormat.indexOf('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 converting 'YY' to 'YYYY' is correct, but ensure that the index used in dateSplit
corresponds to the correct position of 'YY' in fromFormat
.
if (fromFormat.includes('YYYY') && toFormat.includes('YY')) { | ||
result[i] = dateSplit[fromFormat.indexOf('YYYY')].slice(2, 4); | ||
} |
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 index used in dateSplit
corresponds to the correct position of 'YYYY' in fromFormat
when converting to 'YY'.
if (toFormat[i] === fromFormat[0]) { | ||
result[i] = dateSplit[0]; | ||
} | ||
|
||
if (toFormat[i] === fromFormat[1]) { | ||
result[i] = dateSplit[1]; | ||
} | ||
|
||
if (toFormat[i] === fromFormat[2]) { | ||
result[i] = dateSplit[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 for reordering date parts based on toFormat
is correct, but ensure that the indices used in dateSplit
match the positions in fromFormat
.
No description provided.