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

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

add task solution #2704

wants to merge 3 commits into from

Conversation

ABahatiy
Copy link

@ABahatiy ABahatiy commented Nov 1, 2023

No description provided.

Copy link

@lerastarynets lerastarynets 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 overall! Left one tiny suggestion for the improvement


const props = sourceString.split(';')
.map((prop) => prop.replace(/[\n, \s]+/, ''))
.filter((prop) => prop.length > 0);

Choose a reason for hiding this comment

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

Suggested change
.filter((prop) => prop.length > 0);
.filter((prop) => !!prop.length);

@ABahatiy
Copy link
Author

ABahatiy commented Nov 1, 2023

Thank`s for review !

Copy link

@IvanFesenko IvanFesenko left a comment

Choose a reason for hiding this comment

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

Well done

Comment on lines 21 to 35
const props = sourceString.split(';')
.map((prop) => prop.replace(/[\n, \s]+/, ''))
.filter((prop) => !!prop.length);

// create new object for props
const propsObj = {};

// spilt each propetry to key value and assing to object
for (let i = 0; i < props.length; i++) {
const prop = props[i].split(':');

propsObj[prop[0].trim()] = prop[1].trim();
}

return propsObj;

Choose a reason for hiding this comment

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

last loop can be replaces wia Array.reduce()

Suggested change
const props = sourceString.split(';')
.map((prop) => prop.replace(/[\n, \s]+/, ''))
.filter((prop) => !!prop.length);
// create new object for props
const propsObj = {};
// spilt each propetry to key value and assing to object
for (let i = 0; i < props.length; i++) {
const prop = props[i].split(':');
propsObj[prop[0].trim()] = prop[1].trim();
}
return propsObj;
return sourceString.split(';')
.map((prop) => prop.replace(/[\n, \s]+/, ''))
.filter((prop) => !!prop.length)
.reduce((acc, styleRow) => {
const [key, value] = styleRow.split(':');
acc[key.trim()] = value.trim();
return acc;
}, {})

@ABahatiy ABahatiy requested a review from IvanFesenko November 1, 2023 14:03
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