From c68fa6666732a639ef5b33280a0d69f5a5beb3a6 Mon Sep 17 00:00:00 2001 From: Roman Date: Tue, 10 Dec 2024 19:19:20 +0400 Subject: [PATCH] add task solution --- src/convertToObject.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/convertToObject.js b/src/convertToObject.js index 32c556ea4..fd79fa40a 100644 --- a/src/convertToObject.js +++ b/src/convertToObject.js @@ -6,7 +6,17 @@ * @return {object} */ function convertToObject(sourceString) { - // write your code here + return Object.fromEntries( + sourceString + .split(';') + .map((declaration) => declaration.trim()) + .filter(Boolean) + .map((declaration) => { + const [key, value] = declaration.split(':').map((part) => part.trim()); + + return [key, value]; + }), + ); } module.exports = convertToObject;