Skip to content

Commit

Permalink
Solution
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidKuznets committed Nov 21, 2024
1 parent a127773 commit e7feea3
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/convertToObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,19 @@
* @return {object}
*/
function convertToObject(sourceString) {
// write your code here
return sourceString
.split(';')
.map((style) => style.trim())
.filter((style) => style.includes(':'))
.reduce((acc, declaration) => {
const [property, value] = declaration
.split(':')
.map((item) => item.trim());

acc[property] = value;

return acc;
}, {});
}

module.exports = convertToObject;

0 comments on commit e7feea3

Please sign in to comment.