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

add task solution #2172

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

add task solution #2172

wants to merge 2 commits into from

Conversation

mtereshyn
Copy link

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 meets many of the task requirements, there are a few critical issues that need to be addressed to ensure the formatDate function works correctly:

  1. Delimiter Handling: The use of newDeleteLastElement as a delimiter for joining date parts may not align with the expected format in toFormat. Ensure that the delimiter matches the intended output format.

  2. Year Conversion Logic: The conversion from 'YY' to 'YYYY' relies on a hardcoded threshold ('30'), which might not be suitable for all scenarios. Consider making this logic more flexible or configurable to accommodate different use cases.

  3. Handling 'YYYY' in fromFormat: The current logic assumes 'YYYY' is always present in fromFormat, which might not be true. Ensure your code can handle cases where 'YYYY' is absent.

  4. Correct Population of partOfDate: The partOfDate array is not correctly populated. Make sure it accurately reflects the segments of the date string based on fromFormatCopy.

  5. Date String Splitting: The method for splitting the date string using deleteLastElement is flawed. This approach assumes the last element of fromFormat is a delimiter, which may not always be the case. Consider a more robust parsing method.

Please address these issues to ensure the function performs as expected. 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.

Comment on lines 13 to 14
const deleteLastElement = fromFormatCopy.pop();
const partOfDate = date.split(deleteLastElement);

Choose a reason for hiding this comment

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

The logic for splitting the date string using deleteLastElement is incorrect. This assumes that the last element of fromFormat is a delimiter, which may not always be the case. Consider using a more robust method to parse the date string based on the format provided.

const partsOfDate = {};

fromFormatCopy.forEach((part, index) => {
partsOfDate[part] = partOfDate[index];

Choose a reason for hiding this comment

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

The partOfDate array is not correctly populated. Since partOfDate is derived from splitting the date string, ensure that it contains the correct segments corresponding to fromFormatCopy. Otherwise, partsOfDate will not be populated correctly.

Comment on lines 21 to 23
if (toFormatCopy.includes('YY') && partsOfDate['YYYY']) {
partsOfDate['YY'] = partsOfDate['YYYY'].slice(-2);
}

Choose a reason for hiding this comment

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

The conversion from 'YYYY' to 'YY' assumes that 'YYYY' is always present, which might not be the case. Ensure that the logic handles cases where 'YYYY' is not provided in fromFormat.

Comment on lines 25 to 30
if (toFormatCopy.includes('YYYY') && partsOfDate['YY']) {
partsOfDate['YYYY'] =
partsOfDate['YY'] < '30'
? '20' + partsOfDate['YY']
: '19' + partsOfDate['YY'];
}

Choose a reason for hiding this comment

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

The conversion from 'YY' to 'YYYY' is based on a hardcoded threshold ('30'), which might not be suitable for all use cases. Consider making this logic more flexible or configurable.

Comment on lines 32 to 35
const newDeleteLastElement = toFormatCopy.pop();
const newDate = toFormatCopy
.map((part) => partsOfDate[part])
.join(newDeleteLastElement);

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, using newDeleteLastElement as a delimiter for joining the date parts may not be correct. Ensure that the delimiter used matches the expected format in toFormat.

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.

Review Summary

Great job on implementing the formatDate function! 🎉 Your code meets the task requirements, and it's clear you've put in a lot of effort. However, there are a few critical issues that need attention to ensure the function works flawlessly:

  1. Delimiter Handling: The use of newSeparator for joining date parts may not align with the expected format in toFormat. Ensure that the delimiter matches the intended output format.

  2. Year Conversion Logic: The conversion logic from 'YY' to 'YYYY' uses a hardcoded threshold ('30'), which might not be suitable for all scenarios. Consider making this logic more flexible or configurable.

  3. Handling 'YYYY' in fromFormat: The logic assumes that 'YYYY' is always present in fromFormat, which might not be true. Ensure that the code can handle cases where 'YYYY' is absent.

  4. Date String Splitting: The logic assumes that the last element of fromFormat is a separator, which may not always be the case. Consider using a more robust method to determine the separator.

These issues should be addressed in future iterations to avoid similar problems. Keep up the great work, and use this feedback to refine your skills further. Remember, learning from mistakes is a crucial part of the development process. 😊

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

Comment on lines +14 to +15
const separator = fromFormatCopy.pop();
const parts = date.split(separator);

Choose a reason for hiding this comment

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

The logic assumes that the last element of fromFormat is a separator, which may not always be the case. This could lead to incorrect splitting of the date string. Consider using a more robust method to determine the separator.

Comment on lines +23 to +25
if (toFormatCopy.includes('YY') && dateParts['YYYY']) {
dateParts['YY'] = dateParts['YYYY'].slice(-2);
}

Choose a reason for hiding this comment

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

The logic here assumes that 'YYYY' is always present in fromFormat, which might not be true. Ensure that the code can handle cases where 'YYYY' is absent.

Comment on lines +27 to +30
if (toFormatCopy.includes('YYYY') && dateParts['YY']) {
dateParts['YYYY'] =
dateParts['YY'] < '30' ? '20' + dateParts['YY'] : '19' + dateParts['YY'];
}

Choose a reason for hiding this comment

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

The conversion logic from 'YY' to 'YYYY' uses a hardcoded threshold ('30'), which might not be suitable for all scenarios. Consider making this logic more flexible or configurable.

Comment on lines +32 to +36
const newSeparator = toFormatCopy.pop();

const newDate = toFormatCopy
.map((part) => dateParts[part])
.join(newSeparator);

Choose a reason for hiding this comment

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

The use of newSeparator as a delimiter for joining date parts may not align with the expected format in toFormat. Ensure that the delimiter matches the intended output format.

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