Here is my issue:
I am facing a situation where I have two Array objects as follows
var array1 = [{ "id": 1, "name": "potatoe", photo="photo"}, {"id": 2, "name": "budget"}]
var array2 = [{ "id": 1, "name": "potatoeModified"},{ "id": 3, "name":
"UhOhAnotherName"}, {"id": 2, "name": "budget"}]
My goal is to search if the ID object in array1 exists in array 2. If it does, I want to replace the name value. If it doesn't exist, like with id 3, I want to add it.
The expected result would be
[{ "id": 1, "name": "potatoeModified", photo="photo"}, {"id": 2, "name": "budget"},
{ "id": 3, "name": "UhOhAnotherName"}]
I have attempted to achieve this, but each time I end up with a function that has too high of a cyclomatic complexity. I do not want one massive function for this task. I believe the solution is straightforward, yet I seem to be missing something... Thank you :)