In my Javascript code, I have an array of objects structured like this:
var arrobj = [
{'id': 1, 'editors': 'Andrew||Maria', 'authors': 'Dorian||Gabi', 'agents': 'Bob||Peter'},
{'id': 2, 'editors': 'Dorian||Guybrush', 'author': 'Peter||Frodo', 'agents': 'Dorian||Otto'},
{'id': 3, 'editors': 'Klaus||Otmar', 'authors': 'Jordan||Morgan', 'agents': 'Jordan||Peter'},
];
My task is to create a list of all individuals (editors, authors & agents) mentioned in each object along with their respective roles. The desired output should include a new key/value-pair ('involved') formatted as follows:
'involved': 'Andrew (editor)|| Maria (editor)|| Dorian (author) || Gabi (author) || Bob (agent) || Peter (agent)'
The modified array of objects should look like this:
var arrobj = [
{'id': 1, 'editors': 'Andrew||Maria', 'authors': 'Dorian||Gabi', 'agents': 'Bob||Peter', 'involved': 'Andrew (editor)|| Maria (editor)|| Dorian (author) || Gabi (author) || Bob (agent) || Peter (agent)'},
{'id': 2, 'editors': 'Dorian||Guybrush', 'authors': 'Peter||Frodo', 'agents': 'Dorian||Otto','involved': 'Dorian (editor, agent) || Guybrush (editor) || Peter (author) || Frodo (author) || Otto (author)'},
{'id': 3, 'editors': 'Klaus||Otmar', 'authors': 'Jordan||Morgan', 'agents': 'Jordan||Peter','involved': 'Klaus (editor) || Otmar (editor) || Jordan (author, agent) || Morgan (author) || Peter (agent)'},
];
If an individual plays multiple roles (e.g. in id 2 -> Dorian appears as both editor and agent), their name should only appear once in 'involved' but with all roles listed in brackets (e.g. Dorian (editor, agent))
As a beginner in programming, I am unsure how to approach this problem effectively. I believe the first step is to split all values by "||" into arrays and then compare each name with every other name in the array.
I would greatly appreciate any guidance or assistance on this issue.