diff --git a/src/convertToObject.js b/src/convertToObject.js index 32c556ea4..a94e18368 100644 --- a/src/convertToObject.js +++ b/src/convertToObject.js @@ -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;