-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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 #3686
base: master
Are you sure you want to change the base?
Solution #3686
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,26 @@ | |
* @return {object} | ||
*/ | ||
function convertToObject(sourceString) { | ||
// write your code here | ||
const styles = {}; | ||
|
||
if (sourceString.length === 0) { | ||
return styles; | ||
} | ||
|
||
sourceString | ||
.split(';') | ||
.map((el) => el.trim()) | ||
.filter((el) => el.includes(':')) | ||
.forEach((el) => { | ||
const [key, ...values] = el.split(':'); | ||
const value = values.join(':').trim(); | ||
Comment on lines
+20
to
+21
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The use of |
||
|
||
if (key && value) { | ||
styles[key.trim()] = value; | ||
Comment on lines
+23
to
+24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ensure that both |
||
} | ||
}); | ||
|
||
return styles; | ||
} | ||
|
||
module.exports = convertToObject; |
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.
reduce
to generate an object with it