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 #2197

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

solution #2197

wants to merge 1 commit into from

Conversation

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

Great job on implementing the formatDate function to meet the task requirements! 🎉 While there are some minor issues with the use of splice instead of split, your solution effectively handles the conversion of date formats, including changing separators and reordering date parts. Keep up the good work, and consider refining the string handling for even better code quality in the future. 😊

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

function formatDate(date, fromFormat, toFormat) {
// write code here
const separator = fromFormat.splice(3, 1);

Choose a reason for hiding this comment

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

The splice method is used incorrectly here. splice is an array method, but fromFormat is expected to be an array of strings. You should use split to separate the format string into components if needed.

function formatDate(date, fromFormat, toFormat) {
// write code here
const separator = fromFormat.splice(3, 1);
const newSeparator = toFormat.splice(3, 1);

Choose a reason for hiding this comment

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

Similar to the previous line, splice is incorrectly used here. Use split to handle string separation.

Comment on lines +10 to +16
if (fromFormat.includes('YY') && toFormat.includes('YYYY')) {
if (dateSplit[fromFormat.indexOf('YY')] < 30) {
result[i] = `20${dateSplit[fromFormat.indexOf('YY')]}`;
} else {
result[i] = `19${dateSplit[fromFormat.indexOf('YY')]}`;
}
}

Choose a reason for hiding this comment

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

The logic for converting 'YY' to 'YYYY' is correct, but ensure that the index used in dateSplit corresponds to the correct position of 'YY' in fromFormat.

Comment on lines +18 to +20
if (fromFormat.includes('YYYY') && toFormat.includes('YY')) {
result[i] = dateSplit[fromFormat.indexOf('YYYY')].slice(2, 4);
}

Choose a reason for hiding this comment

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

Ensure that the index used in dateSplit corresponds to the correct position of 'YYYY' in fromFormat when converting to 'YY'.

Comment on lines +22 to +32
if (toFormat[i] === fromFormat[0]) {
result[i] = dateSplit[0];
}

if (toFormat[i] === fromFormat[1]) {
result[i] = dateSplit[1];
}

if (toFormat[i] === fromFormat[2]) {
result[i] = dateSplit[2];
}

Choose a reason for hiding this comment

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

The logic for reordering date parts based on toFormat is correct, but ensure that the indices used in dateSplit match the positions in fromFormat.

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