From bae75cde4dc9f39b0f2a20687a20eb685ab31026 Mon Sep 17 00:00:00 2001 From: Maxim Reznichenko Date: Wed, 16 Oct 2024 18:33:04 +0300 Subject: [PATCH] Solution --- src/convertToObject.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/convertToObject.js b/src/convertToObject.js index 7527704d..27b6fc45 100644 --- a/src/convertToObject.js +++ b/src/convertToObject.js @@ -1,19 +1,19 @@ function convertToObject(sourceString) { - const styles = {}; - - sourceString + return sourceString .split(';') - .filter(line => line.trim()) - .forEach(line => { + .filter((line) => line.trim()) + .reduce((acc, line) => { const [property, value] = line.split(':'); + if (property && value) { - const key = property.trim(); - const val = value.trim(); - styles[key] = val; + const trimmedProperty = property.trim(); + const trimmedValue = value.trim(); + + acc[trimmedProperty] = trimmedValue; } - }); - return styles; + return acc; + }, {}); } module.exports = convertToObject;