Skip to content

Commit

Permalink
Solution
Browse files Browse the repository at this point in the history
  • Loading branch information
solyaqw committed Nov 25, 2024
1 parent a127773 commit 05c9d22
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/convertToObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,18 @@
* @return {object}
*/
function convertToObject(sourceString) {
// write your code here
const styleObject = {};
const lines = sourceString.split(';').filter((line) => line.trim());

for (const line of lines) {
const [key, value] = line.split(':').map((part) => part && part.trim());

if (key && value) {
styleObject[key] = value.replace(';', '');
}
}

return styleObject;
}

module.exports = convertToObject;

0 comments on commit 05c9d22

Please sign in to comment.