-
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 added #2271
base: master
Are you sure you want to change the base?
Solution added #2271
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! 🎉 While there are a few assumptions in your code, such as the handling of two-digit years and separator positions, these do not critically impact the functionality. Consider documenting these assumptions or making them configurable for greater flexibility. Keep up the good work and continue refining your skills! 😊
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
@@ -9,6 +9,41 @@ | |||
*/ | |||
function formatDate(date, fromFormat, toFormat) { | |||
// write code here | |||
const data = {}; | |||
let newDataStr = ''; | |||
let separator = 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 assumption that the separator is always at index 3 of the fromFormat
array may not be correct. Consider checking for the separator dynamically or ensuring that the format arrays are structured to meet this assumption.
} | ||
} | ||
|
||
separator = 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 previous comment, the assumption about the separator's position in the toFormat
array might not always hold true. Ensure that the separator is correctly identified or that the format arrays are structured accordingly.
data[fromFormat[i]] = dateArr[i]; | ||
|
||
if (fromFormat[i] === 'YYYY') { | ||
data.YY = dateArr[i] % 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 calculation for data.YY
is correct, but it might be clearer to explicitly convert the year to a string and slice the last two characters, especially if the input is expected to be a string.
|
||
if (fromFormat[i] === 'YY') { | ||
if (dateArr[i] < 30) { | ||
data.YYYY = 2000 + +dateArr[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 logic for handling two-digit years assumes that any year less than 30 belongs to the 2000s. This might not be suitable for all applications. Consider making this logic configurable or documenting this assumption clearly.
No description provided.