-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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 #2186
base: master
Are you sure you want to change the base?
add task solution #2186
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 code meets the task requirements and constraints, handling date format conversions effectively. While there are some assumptions in your code regarding delimiters and date components, these don't impact the core functionality for the specified task. For future improvements, consider making your code more flexible to handle a wider variety of date formats and configurations. Keep up the good work! 😊
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
@@ -8,7 +8,32 @@ | |||
* @returns {string} | |||
*/ | |||
function formatDate(date, fromFormat, toFormat) { | |||
// write code here | |||
const tempArr = 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 code assumes that the delimiter is always at index 3 of the fromFormat
array. This might not be the case for all date formats. Consider making the delimiter dynamic or configurable.
const tempArr = date.split(fromFormat[3]); | ||
const resultArr = []; | ||
|
||
for (let i = 0; i <= 2; 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 assumes that there are always three components in the date format (e.g., day, month, year). This might not hold true for all date formats. Consider making the loop adaptable to different numbers of components.
for (let n = 0; n <= 2; n++) { | ||
if (toFormat[i][0] === fromFormat[n][0]) { | ||
if (toFormat[i].length < fromFormat[n].length) { | ||
resultArr[i] = +tempArr[n] % 100; |
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 for two-digit years assumes that any two-digit year is in the 20th century if it's less than 30. This assumption might not be valid for all use cases. Consider making this logic more flexible or configurable.
} | ||
} | ||
|
||
return resultArr.join(toFormat[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.
Similar to the issue with fromFormat
, the code assumes that the delimiter for toFormat
is at index 3. Ensure that this assumption holds for all expected formats or make it configurable.
No description provided.