Skip to content

Commit

Permalink
Solution
Browse files Browse the repository at this point in the history
  • Loading branch information
Mihakurochkin committed Dec 30, 2024
1 parent a127773 commit 7cced10
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/convertToObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,28 @@
* @return {object}
*/
function convertToObject(sourceString) {
// write your code here
const cleanedStyles = sourceString
.split(';')
.map((style) => style.trim())
.filter(Boolean);
const result = {};

cleanedStyles.forEach((style) => {
const colonIndex = style.indexOf(':');

if (colonIndex === -1) {
return;
}

const property = style.slice(0, colonIndex).trim();
const value = style.slice(colonIndex + 1).trimStart();

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

return result;
}

module.exports = convertToObject;

0 comments on commit 7cced10

Please sign in to comment.