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 added #2271

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

Solution added #2271

wants to merge 1 commit into from

Conversation

romka12254
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! 🎉 While there are a few assumptions in your code, such as the handling of two-digit years and separator positions, these do not critically impact the functionality. Consider documenting these assumptions or making them configurable for greater flexibility. Keep up the good work and continue refining your skills! 😊

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

@@ -9,6 +9,41 @@
*/
function formatDate(date, fromFormat, toFormat) {
// write code here
const data = {};
let newDataStr = '';
let separator = fromFormat[3];

Choose a reason for hiding this comment

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

The assumption that the separator is always at index 3 of the fromFormat array may not be correct. Consider checking for the separator dynamically or ensuring that the format arrays are structured to meet this assumption.

}
}

separator = toFormat[3];

Choose a reason for hiding this comment

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

Similar to the previous comment, the assumption about the separator's position in the toFormat array might not always hold true. Ensure that the separator is correctly identified or that the format arrays are structured accordingly.

data[fromFormat[i]] = dateArr[i];

if (fromFormat[i] === 'YYYY') {
data.YY = dateArr[i] % 100;

Choose a reason for hiding this comment

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

The calculation for data.YY is correct, but it might be clearer to explicitly convert the year to a string and slice the last two characters, especially if the input is expected to be a string.


if (fromFormat[i] === 'YY') {
if (dateArr[i] < 30) {
data.YYYY = 2000 + +dateArr[i];

Choose a reason for hiding this comment

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

The logic for handling two-digit years assumes that any year less than 30 belongs to the 2000s. This might not be suitable for all applications. Consider making this logic configurable or documenting this assumption clearly.

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