Skip to content

Commit

Permalink
Solution
Browse files Browse the repository at this point in the history
  • Loading branch information
Sibunas committed Nov 9, 2023
1 parent be580c2 commit 4d1c6d7
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/convertToObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,28 @@
/**
* Implement convertToObject function:
*
* Function takes a string with styles (see an example in [stylesString.js](./stylesString.js))
* Function takes a string with styles
* (see an example in [stylesString.js](./stylesString.js))
* and returns an object where CSS properties are keys
* and values are the values of related CSS properties (see an exampl in [test file](./convertToObject.test.js))
* and values are the values of related CSS properties
* (see an exampl in [test file](./convertToObject.test.js))
*
* @param {string} sourceString
*
* @return {object}
*/
function convertToObject(sourceString) {
// write your code here
}
const styleObject = {};
const properties = sourceString.split(';');

properties.forEach(property => {
const [key, value] = property.split(':');

if (key.trim() && value.trim()) {
styleObject[key.trim()] = value.trim();
}
});

return styleObject;
}
module.exports = convertToObject;

0 comments on commit 4d1c6d7

Please sign in to comment.