From c7085cff6fea608c0cb8b35cd1fccb784d4c8648 Mon Sep 17 00:00:00 2001 From: Mateusz Cieplak Date: Sun, 10 Nov 2024 17:11:48 +0100 Subject: [PATCH] Solution --- src/convertToObject.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/convertToObject.js b/src/convertToObject.js index 32c556ea4..83906f02a 100644 --- a/src/convertToObject.js +++ b/src/convertToObject.js @@ -7,6 +7,18 @@ */ function convertToObject(sourceString) { // write your code here + const styles = sourceString.split(';').filter((style) => style.length !== 0); + const result = {}; + + styles.forEach((style) => { + const [key, value] = style.split(':'); + + if (key && value) { + result[key.trim()] = value.trim(); + } + }); + + return result; } module.exports = convertToObject;