I know I can implement a solution like the following one: Remove duplicate objects from an array using javascript, that is the concatenation of items outputting a string.
However, since my object (or array) representing a network flow must contain 4 or more items (i.e., Source IP, Destination IP, Source Port, Destination Port) in different positions, the concatenation is not helpful here since I should create 4 permutation-strings to compare them. So I'm trying to understand if a more efficient solution exists.
Assuming to have the following 4 objects in javascript:
1. { srcip: 192.168.1.10, dstip: 192.168.1.20, srcport: 5000, dstport: 443 }
2. { srcip: 192.168.1.20, dstip: 192.168.1.10, srcport: 443, dstport: 5000 }
3. { srcip: 192.168.1.10, dstip: 192.168.1.20, srcport: 5000, dstport: 80 }
4. { srcip: 192.168.1.30, dstip: 192.168.1.20, srcport: 5000, dstport: 443 }
only objects 1 and 2 are duplicate; in other words, objects are duplicate when all their elements are identical, even if they are swapped (Source IP with Destination IP and Source Port with Destination Port). Of course, the same data can be stored in array, no matter.
1. [192.168.1.10, 192.168.1.20, 5000, 443]
2. [192.168.1.20, 192.168.1.10, 443, 5000]
3. [192.168.1.10, 192.168.1.20, 5000, 80]
4. [192.168.1.30, 192.168.1.20, 5000, 443]
Do you have any idea how to solve this issue?
UPDATE
Reading your comments and solutions, I just want to add a clarification. An object must be equal to another if the two pairs "IP/ports" are identical, even if they are switched. So, as described above, flow 1 and 2 should be equal, but the following flow is different:
{ srcip: 192.168.1.20, dstip: 192.168.1.10, srcport: 5000, dstport: 443 }
since only its IPs are switched (but not ports) with respect to flow 1.