Skip to content

Commit

Permalink
solution
Browse files Browse the repository at this point in the history
  • Loading branch information
newqou committed Oct 7, 2023
1 parent be580c2 commit ecb1697
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions src/convertToObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,35 @@
/**
* Implement convertToObject function:
*
* Function takes a string with styles (see an example in [stylesString.js](./stylesString.js))
* Function takes a string with styles
* (see an example in [stylesString.js](./stylesString.js))
* and returns an object where CSS properties are keys
* and values are the values of related CSS properties (see an exampl in [test file](./convertToObject.test.js))
* and values are the values of related CSS properties
* (see an exampl in [test file](./convertToObject.test.js))
*
* @param {string} sourceString
*
* @return {object}
*/

function convertToObject(sourceString) {
// write your code here
const obj = {};

const stylesArr = sourceString
.split(';')
.map(elem => elem
.replace('\n', '')
.split(':')
.map(property => property.trim())
);

for (const [key, value] of stylesArr) {
if (key) {
obj[key] = value;
}
}

return obj;
}

module.exports = convertToObject;

0 comments on commit ecb1697

Please sign in to comment.