Skip to content

Commit

Permalink
Solution
Browse files Browse the repository at this point in the history
  • Loading branch information
Lexnazar committed Oct 4, 2023
1 parent be580c2 commit 087cfc5
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/convertToObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,32 @@
/**
* 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 arrays = sourceString.split(';');
const resultOblect = {};

for (let i = 0; i < arrays.length; i++) {
const parts = arrays[i].split(':');

if (parts.length === 2) {
const key = parts[0].trim();
const value = parts[1].trim();

resultOblect[key] = value;
}
}

return resultOblect;
}

module.exports = convertToObject;

0 comments on commit 087cfc5

Please sign in to comment.