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 solution #2210

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

Conversation

PolianskyiDmytro
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 the formatDate function! 😊 While your implementation covers many of the task requirements, there are a few critical issues that need to be addressed before we can approve the changes.

  1. Year Conversion Logic: The current logic for converting between 'YY' and 'YYYY' formats has some flaws. Specifically, it does not handle cases where shortYear is zero, and the assumption about years being in the 1900s or 2000s may not always hold true. Consider making this logic more robust or configurable.

  2. Redundant Operations: The date.split(fromSpliter)[i] operation is repeated multiple times within the loop. Optimizing this by storing the split result in a variable before the loop can improve efficiency.

  3. Splitter Logic: The assumption that the last element of the format arrays is the splitter might not always be correct. Please ensure that the format arrays are structured correctly to avoid potential errors.

Once these issues are addressed, your code will be in great shape! Keep up the great work, and I look forward to seeing your improvements. 🚀

✨ 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 +11 to +12
const fromSpliter = fromFormat[fromFormat.length - 1];
const toSpliter = toFormat[toFormat.length - 1];

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 splitters (fromSpliter and toSpliter) assumes that the last element of the format arrays is the splitter. This might not always be correct. Ensure that the format arrays are structured such that the last element is indeed the splitter.

Comment on lines 22 to 28
longYear = date.split(fromSpliter)[i];
} else if (fromFormat[i] === 'YY') {
shortYear = date.split(fromSpliter)[i];
} else if (fromFormat[i] === 'MM') {
month = date.split(fromSpliter)[i];
} else {
day = date.split(fromSpliter)[i];

Choose a reason for hiding this comment

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

The date.split(fromSpliter)[i] operation is repeated multiple times within the loop. Consider splitting the date once before the loop and storing the result in a variable to avoid redundant operations.

Comment on lines 35 to 40
} else if (toFormat[i] === 'YY' && shortYear !== 0) {
dateArray.push(shortYear);
} else if (toFormat[i] === 'YY' && longYear !== 0) {
year += longYear;
year = year.split('').splice(2).join('');
dateArray.push(Number(year));

Choose a reason for hiding this comment

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

The logic for handling 'YY' and 'YYYY' conversions is incorrect. When converting 'YY' to 'YYYY', the code should handle cases where shortYear is zero, which currently isn't addressed. Similarly, when converting 'YYYY' to 'YY', ensure that the conversion logic correctly extracts the last two digits.

Comment on lines 41 to 47
} else if (toFormat[i] === 'YYYY' && shortYear !== 0) {
if (shortYear < 30) {
year += '20' + shortYear;
} else {
year += '19' + shortYear;
}
dateArray.push(Number(year));

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' assumes that years less than 30 are in the 2000s and others are in the 1900s. This assumption may not always be valid. Consider making this logic configurable or more robust.

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! 🎉 While the function has been improved, there are a few areas that need attention to fully meet the task requirements:

  1. Year Conversion Logic: The conversion from 'YY' to 'YYYY' needs to be more robust. Currently, it assumes years less than 30 are in the 2000s, which might not always be accurate. Consider refining this logic to handle edge cases, especially when the year is zero or near a century boundary.

  2. Redundant Operations: Try to optimize the code by reducing redundant operations, such as accessing fromArray[i] multiple times within the loop. Storing the result in a variable before the loop could improve efficiency.

  3. Splitter Logic: The assumption that the last element of the format arrays is the splitter might not always be correct. Revisit this logic to ensure the correct splitter is identified and aligns with the task requirements.

Your effort is commendable, and these improvements will help you enhance your coding skills. Keep up the good work, and make sure to address these issues in future iterations to avoid similar problems. Happy coding! 😊

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

Comment on lines 11 to 12
const fromSpliter = fromFormat[fromFormat.length - 1];
let toSpliter = toFormat[toFormat.length - 1];

Choose a reason for hiding this comment

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

The assumption that the last element of the format arrays is the splitter might not always be correct. Consider revisiting the logic to ensure the correct splitter is identified.

Comment on lines 36 to 41
} else if (toFormat[i] === 'YY' && shortYear !== 0) {
dateArray.push(shortYear);
} else if (toFormat[i] === 'YY' && longYear !== 0) {
year += longYear;
year = year.split('').splice(2).join('');
dateArray.push(Number(year));

Choose a reason for hiding this comment

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

The logic for converting a long year to a short year seems to be correct, but ensure that the conversion handles all edge cases, especially when the year is zero or close to the century boundary.

Comment on lines 42 to 48
} else if (toFormat[i] === 'YYYY' && shortYear !== 0) {
if (shortYear < 30) {
year += '20' + shortYear;
} else {
year += '19' + shortYear;
}
dateArray.push(Number(year));

Choose a reason for hiding this comment

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

The logic for converting a short year to a long year is improved, but it still assumes that years less than 30 are in the 2000s and others are in the 1900s. This assumption might not hold for all cases, so consider making this logic more robust.

Comment on lines 22 to 30
if (fromFormat[i] === 'YYYY') {
longYear = fromArray[i];
} else if (fromFormat[i] === 'YY') {
shortYear = fromArray[i];
} else if (fromFormat[i] === 'MM') {
month = fromArray[i];
} else {
day = fromArray[i];
}

Choose a reason for hiding this comment

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

you can simplify it using the switch case

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.

3 participants