Skip to content

Solution#2672

Open
P3ntagr4ma wants to merge 2 commits into
mate-academy:masterfrom
P3ntagr4ma:develop
Open

Solution#2672
P3ntagr4ma wants to merge 2 commits into
mate-academy:masterfrom
P3ntagr4ma:develop

Conversation

@P3ntagr4ma

Copy link
Copy Markdown

No description provided.

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Review Summary

I am requesting changes because there is a functional logic issue in the nested loops that can break the required behavior. For each toFormat[i], your inner loop over fromFormat[j] can push multiple values into result (for example, on lines where you compare and then transform YY/YYYY), which violates the one-to-one mapping between each target format field and a single date part. This can lead to misaligned or incorrect output strings even when the input date and formats are valid, so it is a critical blocker for the correctness requirement.

To fix this, once you find the matching fromFormat[j] for a given toFormat[i] and push the transformed value into result, you should immediately break out of the inner loop and move on to the next toFormat[i]. That ensures exactly one value is produced for each toFormat position and keeps the ordering and year conversion logic correct. Aside from this control-flow issue, your handling of separators, reordering, and YYYYYY conversions is aligned with the task, and the code structure is generally solid. As a minor improvement (not required to pass), consider renaming variables like mas to something more descriptive like parts to improve readability. With the loop logic corrected, your solution should fully meet the specification.


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

Important

Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.

Tip

If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.

Caution

Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.

Footnotes

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example

Comment thread src/formatDate.js
Comment on lines +16 to +42
for (let i = 0; i < toFormat.length - 1; i++) {
for (let j = 0; j < fromFormat.length - 1; j++) {
if (
toFormat[i] !== fromFormat[j] &&
fromFormat[j] === 'YY' &&
toFormat[i] === 'YYYY'
) {
if (parseInt(mas[j]) < 30) {
mas[j] = '20' + mas[j];
} else {
mas[j] = '19' + mas[j];
}

result.push(mas[j]);
} else if (
toFormat[i] !== fromFormat[j] &&
fromFormat[j] === 'YYYY' &&
toFormat[i] === 'YY'
) {
const numb = mas[j].split('');

mas[j] = numb[2] + numb[3];
result.push(mas[j]);
} else if (toFormat[i] === fromFormat[j]) {
result.push(mas[j]);
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

For each toFormat[i], you keep iterating over all fromFormat[j] and may push multiple items into result, which can misalign the final date parts. Once you find the matching fromFormat[j] and push the correct transformed value, consider breaking out of the inner loop so that exactly one value is added per toFormat element.

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Review Summary

Your solution is approved because it meets all the functional requirements for formatDate and behaves correctly for the specified examples. The function correctly accepts the date string plus fromFormat and toFormat arrays, uses the separator from fromFormat[3] to split and toFormat[3] to join, and reorders the components based on the target format. You’ve also implemented the YYYYYY conversion rules properly: years < 30 are mapped to 20YY, years >= 30 to 19YY, and YYYYYY correctly uses the last two digits. The earlier logical issue of potentially pushing multiple values per output position has been fixed by breaking from the inner loop after a push, ensuring a one-to-one mapping between format tokens and date parts. Any remaining points are minor (for example, optional comments explaining that the 4th element of the format arrays is the separator), and they do not affect correctness. Nicely done implementing the required behavior without adding unnecessary complexity.


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

Footnotes

  1. Rate AI review example

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