Skip to content
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 #2138

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Solution #2138

wants to merge 2 commits into from

Conversation

LX-y-ka
Copy link

@LX-y-ka LX-y-ka commented Oct 26, 2024

No description provided.

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a 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 pull request! 😊 While your solution is on the right track and meets many of the task requirements, there are a few critical issues that need to be addressed before we can approve it:

  1. Undefined format Function: The format function is referenced in your code but is not defined within the provided code. This could lead to runtime errors. Please ensure that this function is implemented or imported correctly.

  2. Delimiter Handling: The way delimiters are handled in both date.split(fromFormat.slice(-1)) and result.join(toFormat.slice(-1)) might not work as expected if the delimiter is not the last character of the format strings. Consider explicitly defining the delimiter or extracting it correctly from the format string to ensure accurate splitting and joining of date components.

Once these issues are addressed, your code should be in great shape! Keep up the great work, and don't hesitate to reach out if you need further clarification or assistance. 🚀

✨ 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.

@@ -9,6 +9,34 @@
*/
function formatDate(date, fromFormat, toFormat) {
// write code here
const result = Array(3).fill(0);
const dateArray = date.split(fromFormat.slice(-1));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The delimiter used in date.split(fromFormat.slice(-1)) might not correctly split the date string if the delimiter is not the last character of fromFormat. Consider explicitly defining the delimiter or extracting it from the format string.

result[toFormat.indexOf('MM')] = month;
result[toFormat.indexOf(yearToFormat)] = formatedYear;

return result.join(toFormat.slice(-1));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to the issue in line 13, using toFormat.slice(-1) as the delimiter in result.join(toFormat.slice(-1)) might not correctly join the date components if the delimiter is not the last character of toFormat. Ensure the correct delimiter is used.

const yearFromFormat = fromFormat.indexOf('YY') === -1 ? 'YYYY' : 'YY';
const year = dateArray[fromFormat.indexOf(yearFromFormat)];
const yearToFormat = toFormat.indexOf('YY') === -1 ? 'YYYY' : 'YY';
const formatedYear = format(year, yearFromFormat, yearToFormat);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The format function is used here but is not defined in the provided code. Ensure that this function is implemented elsewhere or provide its implementation to avoid runtime errors.

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a 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, effectively converting date strings between formats, handling separators, and adjusting year formats as needed.

However, there are a few areas for improvement:

  • Century Logic: The current logic assumes that any year less than 30 belongs to the 21st century. This might not be suitable for all scenarios. Consider making this logic more flexible or configurable.
  • Separator Handling: The logic for determining toSeparator assumes that the last element of toFormat is a separator if it matches the regex. This might not always be accurate, especially if toFormat doesn't explicitly include a separator. Revising this logic could enhance the function's robustness.

These improvements will help you refine your code and avoid potential issues in the future. Keep up the great work and continue learning from these experiences! 🚀

✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨

Comment on lines +15 to +17
const toSeparator = toFormat[toFormat.length - 1].match(/[^\w\s]/)
? toFormat[toFormat.length - 1]
: fromSeparator;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic for determining toSeparator assumes that the last element of toFormat is a separator if it matches the regex. This might not always be true, especially if toFormat doesn't explicitly include a separator. Consider revising this logic to ensure it correctly identifies the intended separator.

}

if (yearToFormat.length > yearFromFormat.length) {
formatedYear = +year < 30 ? '20' + year : '19' + year;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic for determining the century prefix for the year assumes that any year less than 30 belongs to the 21st century. This might not be a valid assumption for all use cases. Consider making this logic more flexible or configurable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants