diff --git a/src/convertToObject.js b/src/convertToObject.js index 32c556ea4..0c1bec91d 100644 --- a/src/convertToObject.js +++ b/src/convertToObject.js @@ -6,7 +6,28 @@ * @return {object} */ function convertToObject(sourceString) { - // write your code here + const cleanedStyles = sourceString + .split(';') + .map((style) => style.trim()) + .filter(Boolean); + const result = {}; + + cleanedStyles.forEach((style) => { + const colonIndex = style.indexOf(':'); + + if (colonIndex === -1) { + return; + } + + const property = style.slice(0, colonIndex).trim(); + const value = style.slice(colonIndex + 1).trimStart(); + + if (property && value) { + result[property] = value; + } + }); + + return result; } module.exports = convertToObject;