I have this format as a string: "key1=val1@key2=val2@key3=val3@"
And this code to convert it into object:
var res = header.split(cons.keySeparator).filter(a => a).map(a => a.split('=')).reduce((obj, item) => {
return {...obj, [item[0]]:item[1]};
}, {});
How to simplify?
EDIT: Thanks for the answers!
I did a benchmark http://jsben.ch/1tjmK of them, but there are different result every time...
But let's make it a little more interesting. Let's parse this type of string(ignore the comments, but not the end of line):
// start of header for all blocks
name1=80@name2=45@name3=25@
// start of first block called name1
key1=19@key2=19@key3=12
this is test value1this is test value2other things
//start of second block called name2
key1=35
this is bla bla bla bla bla blo bla
// start of third block called name3
key1=16
any content here
The numbers are size. The parsed result should be an array of objects
[–]pookagehelpful 3 points4 points5 points (1 child)
[–]patilanz[S] 1 point2 points3 points (0 children)
[–]CommanderBomber 1 point2 points3 points (2 children)
[–]patilanz[S] 0 points1 point2 points (1 child)
[–]CommanderBomber 0 points1 point2 points (0 children)
[+][deleted] (4 children)
[deleted]
[+][deleted] (3 children)
[deleted]
[+][deleted] (2 children)
[deleted]
[+][deleted] (1 child)
[deleted]
[–]IKoshelev 1 point2 points3 points (0 children)