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

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

Conversation

SerhiiUnhurian
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 convertToObject function! 🎉 Your code meets the task requirements and effectively converts a CSS style string into an object. You've used split, map, and filter methods well, and your variable names are mostly descriptive.

While there are a few minor suggestions for improvement, such as ensuring both key and value are defined before processing, and considering a more readable variable name like splitString, these do not impact the core functionality of your solution. Keep up the good work and continue refining your coding skills! 😊

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

@@ -6,7 +6,57 @@
* @return {object}
*/
function convertToObject(sourceString) {
// write your code here
const splittedString = sourceString

Choose a reason for hiding this comment

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

The variable name splittedString is not ideal. Consider renaming it to splitString for better readability.

const convertedToObject = {};

splittedString.forEach((str) => {
const styleArr = str.split(':');

Choose a reason for hiding this comment

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

The split(':') method will not handle cases where there are multiple colons within a style value. Although handling multiple colons is not required, be aware that this could lead to unexpected behavior if such cases are encountered.

const styleArr = str.split(':');
const [key, value] = styleArr;

convertedToObject[key.trim()] = value.trim();

Choose a reason for hiding this comment

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

Ensure that both key and value are defined before attempting to trim and assign them to the convertedToObject. If styleArr does not contain exactly two elements, this could lead to undefined behavior.

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