From 1af8d976693999b1ed8ba304386c7d78c07c188a Mon Sep 17 00:00:00 2001 From: Oskar Koszalka Date: Fri, 6 Dec 2024 13:47:38 +0100 Subject: [PATCH 1/2] Solution --- src/convertToObject.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/convertToObject.js b/src/convertToObject.js index 32c556ea4..01a53dbd6 100644 --- a/src/convertToObject.js +++ b/src/convertToObject.js @@ -6,7 +6,19 @@ * @return {object} */ function convertToObject(sourceString) { - // write your code here + const sourceStringToArray = sourceString + .split(';') + .map((item) => item.trim()) + .filter((item) => item.length > 0); + const sourceStringToObject = Object.fromEntries( + sourceStringToArray.map((item) => { + const [key, value] = item.split(':', 2); + + return [key.trim(), value.trim()]; + }), + ); + + return sourceStringToObject; } module.exports = convertToObject; From b71245daf201a98f1d9adefdee41b9b60fe18b23 Mon Sep 17 00:00:00 2001 From: o-koszalka Date: Fri, 6 Dec 2024 13:51:53 +0100 Subject: [PATCH 2/2] Update convertToObject.js --- src/convertToObject.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/convertToObject.js b/src/convertToObject.js index 01a53dbd6..9f1b85a72 100644 --- a/src/convertToObject.js +++ b/src/convertToObject.js @@ -15,7 +15,7 @@ function convertToObject(sourceString) { const [key, value] = item.split(':', 2); return [key.trim(), value.trim()]; - }), + }) ); return sourceStringToObject;