Givven an object with Key as an Array (of position) and Value as an Array as well:
// Example Object
0,2 : [6, 8, 9]
0,3 : [1, 6, 8]
0,4 : [6, 8]
0,5 : [6, 8]
0,6 : [4, 5, 8, 9]
0,7 : [5, 8]
0,8 : [4, 5, 7, 9]
(it was created like this:
x = {};
x[[0,2]] = [6, 8, 9];
x[[0,3]] = [1, 6, 8];
...
Now, I want to narrow down my object to this, by checking if any number in an Array appears only inside this array, and not in others value’s arrays, then eliminating all the other numbers inside the specific array which holds the unique number.
(Rule: no duplicated inside a given array, so no need to check that):
// Result Object
0,2 : [6, 8, 9]
0,3 : [1]
0,4 : [6, 8]
0,5 : [6, 8]
0,6 : [4, 5, 8, 9] // now 4 becomes also a "loner"
0,7 : [5, 8]
0,8 : [7]
so here in Key [0,3] the Value’s array was narrowed down to just [1] because 1 is a unique number not showing up in the other array.
I’m having trouble thinking of an efficient pattern for this…
The idea here it that i go through every number in every array, and check it against
a Bucket (string) which holds all the numbers from all the arrays, joined. if the first index of the current
x[key][i]in the bucket is the SAME as the last index, it means this number is unique and, thus it’s holding array is reset to hold that number alone.