diff --git a/package.json b/package.json index d65c540f3..acee91480 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "license": "GPL-3.0", "devDependencies": { "@mate-academy/eslint-config": "*", - "@mate-academy/scripts": "^0.3.5", + "@mate-academy/scripts": "^1.2.8", "eslint": "^5.16.0", "eslint-plugin-jest": "^22.4.1", "eslint-plugin-node": "^8.0.1", diff --git a/src/convertToObject.js b/src/convertToObject.js index 44d498c1d..89e38a501 100644 --- a/src/convertToObject.js +++ b/src/convertToObject.js @@ -3,16 +3,27 @@ /** * 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 + return sourceString + .split(';') + .filter(el => el.trim() !== '') + .reduce((total, lines) => { + const [code, value] = lines.split(':'); + + total[code.trim()] = value.trim(); + + return total; + }, {}); } module.exports = convertToObject;