Skip to content

Commit

Permalink
solution
Browse files Browse the repository at this point in the history
  • Loading branch information
b0hdan1 committed Dec 23, 2024
1 parent a127773 commit ad5953c
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/convertToObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,22 @@
* @return {object}
*/
function convertToObject(sourceString) {
// write your code here
if (sourceString.length === 0) {
return {};
}

const convertedOblect = sourceString
.split(';')
.filter((obj) => obj.length > 0)
.reduce((acc, obj) => {
const [key, value] = obj.split(':').map((part) => part.trim());

acc[key] = value;

return acc;
}, {});

return convertedOblect;
}

module.exports = convertToObject;

0 comments on commit ad5953c

Please sign in to comment.