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

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

Conversation

1umamaster
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! 🎉 Your code meets the task requirements and constraints, handling date format conversions effectively. While there are some assumptions in your code regarding delimiters and date components, these don't impact the core functionality for the specified task. For future improvements, consider making your code more flexible to handle a wider variety of date formats and configurations. Keep up the good work! 😊

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

@@ -8,7 +8,32 @@
* @returns {string}
*/
function formatDate(date, fromFormat, toFormat) {
// write code here
const tempArr = date.split(fromFormat[3]);

Choose a reason for hiding this comment

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

The code assumes that the delimiter is always at index 3 of the fromFormat array. This might not be the case for all date formats. Consider making the delimiter dynamic or configurable.

const tempArr = date.split(fromFormat[3]);
const resultArr = [];

for (let i = 0; i <= 2; i++) {

Choose a reason for hiding this comment

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

The loop assumes that there are always three components in the date format (e.g., day, month, year). This might not hold true for all date formats. Consider making the loop adaptable to different numbers of components.

for (let n = 0; n <= 2; n++) {
if (toFormat[i][0] === fromFormat[n][0]) {
if (toFormat[i].length < fromFormat[n].length) {
resultArr[i] = +tempArr[n] % 100;

Choose a reason for hiding this comment

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

The conversion logic for two-digit years assumes that any two-digit year is in the 20th century if it's less than 30. This assumption might not be valid for all use cases. Consider making this logic more flexible or configurable.

}
}

return resultArr.join(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 issue with fromFormat, the code assumes that the delimiter for toFormat is at index 3. Ensure that this assumption holds for all expected formats or make it configurable.

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