Can I write a function that takes in a string made up of a number or “pairs” separated by “|” characters and produces an object as shown below? Each pair has its two components separated internally with commas.
Example:
objectify("a,dog|b,cat|z,rat") --> {a: "dog", b: "cat", z: "rat"}
objectify("one,uno|two,dos") --> {one: "uno", two: "dos"}
Thanks!
FIDDLE
Create an empty object, split the string on
|and iterate over the parts, split again on comma, and use the result as key/value pairs in the object, and return the object when done.