From 4d1c6d777760d56c307537004ac41e82402a2093 Mon Sep 17 00:00:00 2001 From: Kamil Date: Thu, 9 Nov 2023 10:28:03 +0100 Subject: [PATCH] Solution --- src/convertToObject.js | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/convertToObject.js b/src/convertToObject.js index 44d498c1d..a9eadd03a 100644 --- a/src/convertToObject.js +++ b/src/convertToObject.js @@ -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;