Skip to content

Commit

Permalink
add task solution
Browse files Browse the repository at this point in the history
  • Loading branch information
Uusuff committed Dec 28, 2024
1 parent a127773 commit 2f620d3
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/convertToObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,21 @@
* @return {object}
*/
function convertToObject(sourceString) {
// write your code here
const filteredArray = sourceString
.split(';')
.map((el) => el.trim())
.filter(Boolean);
const styleObject = {};

for (const element of filteredArray) {
const [property, value] = element.split(':').map((part) => part.trim());

if (property && value) {
styleObject[property] = value;
}
}

return styleObject;
}

module.exports = convertToObject;

0 comments on commit 2f620d3

Please sign in to comment.