-
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 #2199
base: master
Are you sure you want to change the base?
Solution #2199
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! 🎉 It meets the task requirements and handles date format conversions effectively. While there are some assumptions about the format array lengths, they don't impact the core functionality. Keep up the good work, and consider making the loop conditions more flexible in future projects for enhanced adaptability. 😊
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
@@ -8,7 +8,52 @@ | |||
* @returns {string} | |||
*/ | |||
function formatDate(date, fromFormat, toFormat) { | |||
// write code here | |||
const partsDate = date.split(fromFormat[3]); |
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 fromFormat[3]
to split the date assumes that the separator is always at index 3. This might not be correct if the format array has a different length. Consider dynamically determining the separator based on the format array.
let month = ''; | ||
let year = ''; | ||
|
||
for (let i = 0; i <= 3; i++) { |
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 loop condition i <= 3
assumes that the fromFormat
array always has 4 elements. This might not be the case. Consider using fromFormat.length
to make the loop more flexible.
|
||
const newPartsDate = []; | ||
|
||
for (let i = 0; i <= 3; i++) { |
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 loop, the condition i <= 3
assumes a fixed length for the toFormat
array. Use toFormat.length
to ensure the loop adapts to different format lengths.
No description provided.