diff --git a/src/convertToObject.js b/src/convertToObject.js index 44d498c1d..7e19b7ecd 100644 --- a/src/convertToObject.js +++ b/src/convertToObject.js @@ -1,18 +1,19 @@ 'use strict'; -/** - * Implement convertToObject function: - * - * 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)) - * - * @param {string} sourceString - * - * @return {object} - */ function convertToObject(sourceString) { - // write your code here + const noTransfer = sourceString.replace(/\n/g, ''); + const sourceArr = noTransfer.split(';'); + const result = {}; + + for (let i = 0; i < sourceArr.length; i++) { + const arrayValue = sourceArr[i].split(':'); + + if (arrayValue[1] !== undefined) { + result[arrayValue[0].trim()] = arrayValue[1].trim(); + } + } + + return result; } module.exports = convertToObject;