I have a 2d array data like this:
var arr = [[a,1,b,10],[c,3,d,30],[a,2,b,20],[c,4,d,40]];
I wanted to achieve this result:
[[a,3,b,30],[c,7,d,70]]
I am thinking of sorting it and looping each element array then compare the 2 sub-elements with the ones in the previous element array but this is not efficient.
What the fastest way to do it? My actual data is thousands of lines. Thank you.
aandbalways go together? Is this a valid array:[a,1,c,2]?