I am a novice. At present, I have encountered some confusion when learning set
data types in Es6, as follows:
in the Es6 about Ruan Yifeng, it is mentioned that set
types can be used to intersect and judge sets, but I have tried it unsuccessfully. I would like to ask what the problem is
Code
var a = new Set([[0, 1], [0, 0], [0, 2]])
var b = new Set([[0, 0], [0, 1]])
var union = new Set([...a, ...b]);
var intersect = new Set([...b].filter(x => a.has(x)));
console.log(union, intersect);
for the first union
, there are still five results, all the elements in an and b are grouped together, but I think it shouldn"t be just a, because some of the elements in b are exactly the same as those in a
for the second intersect
, the result is directly an empty set
, but it should not be b if it is an intersection.
in addition, suppose I want to implement this function, how can I write code pull implementation for this set, which is a bit like a multi-dimensional array?
my level is still shallow, hope to correct