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

resolving task #3676

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

resolving task #3676

wants to merge 2 commits into from

Conversation

Daniil-102
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 this! 😊 While your implementation of convertToObject is mostly correct, there are a few critical issues that need to be addressed before we can approve the pull request:

  1. Iteration Methods: The task requires using iteration methods like map or filter instead of loops. Your current use of a for...of loop does not meet this requirement. Please refactor your code to use these methods.

  2. Handling Malformed Input: It's important to ensure that the function can handle malformed CSS strings gracefully. Consider adding checks to ensure that both style[0] and style[1] are defined before assigning them to the object. Additionally, verify that the style array contains exactly two elements after splitting to prevent potential runtime errors.

  3. Variable Naming: The variable stylesArray could be more descriptive to enhance readability. Consider renaming it to something that clearly indicates its purpose.

These changes are crucial for meeting the task's core requirements and ensuring the robustness of your solution. Once you've addressed these points, feel free to resubmit. Keep up the great work! 🚀

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

continue;
}

style = style.split(':').map((s) => s.trim());

Choose a reason for hiding this comment

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

Consider adding a check to ensure that the style array contains exactly two elements after splitting. This will prevent errors if the input string contains malformed styles without a colon or with multiple colons.

}

style = style.split(':').map((s) => s.trim());
objectOfStyles[style[0]] = style[1];

Choose a reason for hiding this comment

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

Before assigning style[1] to objectOfStyles[style[0]], ensure that both style[0] and style[1] are not undefined. This will help avoid potential runtime errors if the input string is not well-formed.

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 convertToObject function! 🎉 Your code meets the task requirements and constraints, effectively converting a string of CSS styles into an object. You've used iteration methods appropriately and adhered to the checklist's guidelines on variable naming and code style.

However, there are a couple of areas for improvement to enhance the robustness of your solution:

  1. Splitting Logic: Ensure that the split(':') operation results in exactly two parts to avoid potential errors. Consider handling cases where the split does not produce two elements to prevent unexpected behavior.

  2. Filtering Condition: The current filter condition style.length > 3 might not be sufficient for all valid CSS properties. It would be beneficial to check if the style contains a colon : to ensure it's a valid property-value pair.

These improvements will help you write more resilient code. Keep up the great work, and continue learning from these experiences! 🚀

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

sourceString
.split(';')
.map((style) => style.trim())
.filter((style) => style.length > 3)

Choose a reason for hiding this comment

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

The filter condition style.length > 3 might not be sufficient for all valid CSS properties. Consider checking if the style contains a colon : to ensure it's a valid property-value pair.

.map((style) => style.trim())
.filter((style) => style.length > 3)
.forEach((style) => {
const [property, value] = style.split(':').map((part) => part.trim());

Choose a reason for hiding this comment

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

Ensure that the split(':') operation results in exactly two parts to avoid potential errors. You might want to handle cases where the split does not produce two elements.

Copy link

@BudnikOleksii BudnikOleksii left a comment

Choose a reason for hiding this comment

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

👍

.split(';')
.map((style) => style.trim())
.filter((style) => style.length > 3)
.forEach((style) => {

Choose a reason for hiding this comment

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

You can use reduce to generate an object

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