集合運算
任何可迭代物件的邏輯集合運算。
difference(iterable, ...others)
原始碼 · 傳回一個新的 InternSet,包含 iterable 中不存在於任何 others 可迭代物件中的所有值。
js
d3.difference([0, 1, 2, 0], [1]) // Set {0, 2}
union(...iterables)
原始碼 · 傳回一個新的 InternSet,包含出現在任何給定 iterables 中的所有(相異)值。傳回集合中值的順序取決於它們在給定 iterables 中首次出現的順序。
js
d3.union([0, 2, 1, 0], [1, 3]) // Set {0, 2, 1, 3}
intersection(...iterables)
原始碼 · 傳回一個新的 InternSet,包含出現在所有給定 iterables 中的所有(相異)值。傳回集合中值的順序取決於它們在給定 iterables 中首次出現的順序。
js
d3.intersection([0, 2, 1, 0], [1, 3]) // Set {1}
superset(a, b)
原始碼 · 如果 a 是 b 的超集,則傳回 true:如果給定可迭代物件 b 中的每個值也存在於給定可迭代物件 a 中。
js
d3.superset([0, 2, 1, 3, 0], [1, 3]) // true
subset(a, b)
原始碼 · 如果 a 是 b 的子集,則傳回 true:如果給定可迭代物件 a 中的每個值也存在於給定可迭代物件 b 中。
js
d3.subset([1, 3], [0, 2, 1, 3, 0]) // true
disjoint(a, b)
原始碼 · 如果 a 和 b 不相交(如果 a 和 b 不包含任何共用值),則傳回 true。
js
d3.disjoint([1, 3], [2, 4]) // true