diff --git a/src/convertToObject.js b/src/convertToObject.js index 32c556ea4..9f1b85a72 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;