From 353be0dc49a36c0b4853a65cd5a708ca414f4f75 Mon Sep 17 00:00:00 2001 From: Vitalii Date: Fri, 27 Dec 2024 22:42:24 +0000 Subject: [PATCH] solution --- src/convertToObject.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/convertToObject.js b/src/convertToObject.js index 32c556ea4..7887e9dbd 100644 --- a/src/convertToObject.js +++ b/src/convertToObject.js @@ -5,8 +5,17 @@ * * @return {object} */ -function convertToObject(sourceString) { - // write your code here +function convertToObject(styleStr) { + const styleObj = {}; + const styleArr = styleStr.split(';'); + + styleArr.forEach((style) => { + const [key, value] = style.split(':').map((s) => s.trim()); + + styleObj[key] = value; + }); + + return styleObj; } module.exports = convertToObject;