Skip to content

集合运算

¥Set operations

适用于任何可迭代对象的逻辑集合运算。

¥Logical set operations for any iterable.

difference(iterable, ...others)

源代码 · 返回一个新的 InternSet,其中包含可迭代对象中不存在于其他任何可迭代对象中的每个值。

¥Source · Returns a new InternSet containing every value in iterable that is not in any of the others iterables.

js
d3.difference([0, 1, 2, 0], [1]) // Set {0, 2}

union(...iterables)

源代码 · 返回一个新的 InternSet,其中包含任何给定可迭代对象中出现的每个(不同)值。返回集合中值的顺序基于它们在给定可迭代对象中的首次出现。

¥Source · Returns a new InternSet containing every (distinct) value that appears in any of the given iterables. The order of values in the returned set is based on their first occurrence in the given iterables.

js
d3.union([0, 2, 1, 0], [1, 3]) // Set {0, 2, 1, 3}

intersection(...iterables)

源代码 · 返回一个新的 InternSet,其中包含所有给定可迭代对象中出现的每个(不同)值。返回集合中值的顺序基于它们在给定可迭代对象中的首次出现。

¥Source · Returns a new InternSet containing every (distinct) value that appears in all of the given iterables. The order of values in the returned set is based on their first occurrence in the given iterables.

js
d3.intersection([0, 2, 1, 0], [1, 3]) // Set {1}

superset(a, b)

源代码 · 如果 a 是 b 的超集,则返回 true:如果给定可迭代对象 b 中的每个值也存在于给定可迭代对象 a 中。

¥Source · Returns true if a is a superset of b: if every value in the given iterable b is also in the given iterable a.

js
d3.superset([0, 2, 1, 3, 0], [1, 3]) // true

subset(a, b)

源代码 · 如果 a 是 b 的子集,则返回 true:如果给定可迭代对象 a 中的每个值也存在于给定可迭代对象 b 中。

¥Source · Returns true if a is a subset of b: if every value in the given iterable a is also in the given iterable b.

js
d3.subset([1, 3], [0, 2, 1, 3, 0]) // true

disjoint(a, b)

源代码 · 如果 a 和 b 不相交,则返回 true:如果 a 和 b 不包含共享值。

¥Source · Returns true if a and b are disjoint: if a and b contain no shared value.

js
d3.disjoint([1, 3], [2, 4]) // true