-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
base: master
Are you sure you want to change the base?
add task solution #2704
Conversation
There was a problem hiding this 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
src/convertToObject.js
Outdated
|
||
const props = sourceString.split(';') | ||
.map((prop) => prop.replace(/[\n, \s]+/, '')) | ||
.filter((prop) => prop.length > 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.filter((prop) => prop.length > 0); | |
.filter((prop) => !!prop.length); |
Thank`s for review ! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well done
src/convertToObject.js
Outdated
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; |
There was a problem hiding this comment.
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()
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; | |
}, {}) |
No description provided.