-
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
solution #3744
base: master
Are you sure you want to change the base?
solution #3744
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 |
---|---|---|
|
@@ -5,8 +5,19 @@ | |
* | ||
* @return {object} | ||
*/ | ||
function convertToObject(sourceString) { | ||
// write your code here | ||
function convertToObject(styles) { | ||
const styleObject = {}; | ||
const declarations = styles.split(';'); | ||
|
||
declarations.forEach((declaration) => { | ||
const [property, value] = declaration.split(':'); | ||
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. When splitting the declaration by ':', there might be cases where the value itself contains colons (e.g., URLs). Consider using a more robust parsing method to handle such cases. |
||
|
||
if (property && value) { | ||
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 condition |
||
styleObject[property.trim()] = value.trim(); | ||
} | ||
}); | ||
|
||
return styleObject; | ||
} | ||
|
||
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.
The function parameter is named
styles
, but the JSDoc comment refers to it assourceString
. Ensure consistency between the parameter name and the JSDoc comment.