Skip to content

Commit

Permalink
change task solution
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Rich committed Nov 1, 2023
1 parent 49f5c13 commit 5696310
Showing 1 changed file with 7 additions and 14 deletions.
21 changes: 7 additions & 14 deletions src/convertToObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,16 @@
function convertToObject(sourceString) {
// write your code here

// split all props to separate strings

const props = sourceString.split(';')
return sourceString.split(';')
.map((prop) => prop.replace(/[\n, \s]+/, ''))
.filter((prop) => !!prop.length);

// create new object for props
const propsObj = {};

// spilt each propetry to key value and assing to object
for (let i = 0; i < props.length; i++) {
const prop = props[i].split(':');
.filter((prop) => !!prop.length)
.reduce((acc, styleRow) => {
const [key, value] = styleRow.split(':');

propsObj[prop[0].trim()] = prop[1].trim();
}
acc[key.trim()] = value.trim();

return propsObj;
return acc;
}, {});
}

module.exports = convertToObject;

0 comments on commit 5696310

Please sign in to comment.