Skip to content

Commit

Permalink
Solution
Browse files Browse the repository at this point in the history
  • Loading branch information
Tetiana01 committed Nov 25, 2024
1 parent e55dae5 commit a6e0774
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/convertToObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,22 @@
*
* @return {object}
*/
function convertToObject(sourceString) {
// write your code here
function convertToObject(stylesString) {
return stylesString
.split(';')
.map((line) => line.trim())
.filter((line) => line)
.reduce((stylesObject, declaration) => {
const [property, value] = declaration
.split(':')
.map((part) => part.trim());

if (property && value) {
stylesObject[property] = value;
}

return stylesObject;
}, {});
}

module.exports = convertToObject;

0 comments on commit a6e0774

Please sign in to comment.