From ba4fafe696a72f9ceb79c566fb3aef599e1a70c5 Mon Sep 17 00:00:00 2001 From: RomanHasiuk Date: Mon, 9 Dec 2024 14:12:08 +0200 Subject: [PATCH] Solution --- src/convertToObject.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/convertToObject.js b/src/convertToObject.js index 32c556ea4..546ca4f80 100644 --- a/src/convertToObject.js +++ b/src/convertToObject.js @@ -6,7 +6,22 @@ * @return {object} */ function convertToObject(sourceString) { - // write your code here + const styleObject = {}; + const rules = sourceString.split(';'); + + for (let rule of rules) { + rule = rule.trim(); + + if (rule) { + const [key, value] = rule.split(':').map((part) => part.trim()); + + if (key && value) { + styleObject[key] = value; + } + } + } + + return styleObject; } module.exports = convertToObject;