I have a JavaScript array of arrays with different data types that looks like this:
let bigArray = [["A", "B", 221.67],["C", "B", 221.65],["B", "D", 183.33],["B", "A", 4900],["E", "B", 150],["A", "B", 150]]
Now I need to add the third element (a number) if the first and second elements match with the next array's first and second elements, and also subtract the third elements if a reverse match is found.
The expected output will be:
let ans = [["B", "A", 4528.33],["C", "B", 221.65],["B", "D", 183.33],["E", "B", 150]]
The subarray ["B","A", 4528.33] is achieved by performing subtraction operation as 4900-221.67-150
In bigArray, there are arrays with repeated pairs of elements such as "A" and "B". For all matching subarrays, perform addition and for reverse matches, perform subtraction. Example: 4900-221.67-150
I have tried various methods but couldn't achieve the desired output consistently. Any assistance would be greatly appreciated. Thank you!