Skip to content

Commit

Permalink
solution
Browse files Browse the repository at this point in the history
  • Loading branch information
OlegMysko committed Dec 23, 2024
1 parent 7b89326 commit 90eb86c
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/convertToObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,15 @@
* @return {object}
*/
function convertToObject(sourceString) {
const resultObject = {};
const resultArray = sourceString.split(';');

for (const element of resultArray) {
return sourceString.split(';').reduce((accumulator, element) => {
const [key, value] = element.split(':').map((part) => part.trim());

resultObject[key] = value;
}
if (key && value) {
accumulator[key] = value;
}

return resultObject;
return accumulator;
}, {});
}

module.exports = convertToObject;

0 comments on commit 90eb86c

Please sign in to comment.