A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Set/isDisjointFrom below:

Set.prototype.isDisjointFrom() - JavaScript | MDN

Set.prototype.isDisjointFrom()

Baseline 2024

Newly available

isDisjointFrom() は Set インスタンスのメソッドで、集合を取り、この Set に与えられた集合と共通する要素がないことを示す論理値を返します。

構文 引数
other

Set オブジェクト、または Set 風オブジェクトです。

返値

この Set に other の集合と共通する要素がない場合は true、そうでなければ false です。

解説

共通する要素を持たない 2 つの集合は、互いに素です。数学的な表記では、次のようになります。

A  is disjoint from  B ⇔ A ∩ B = ∅ A\text{ is disjoint from }B \Leftrightarrow A\cap B = \empty

ベン図を使うとこうなります。

isDisjointFrom() は、Set 風オブジェクトを other 引数として受け入れます。this は、ユーザーコードを呼び出すことなく、this オブジェクトに格納されているデータに直接アクセスするため、実際の Set インスタンスであることが要求されます。その後、その動作は this と other のサイズに依存します。

この実装により、isDisjointFrom() の実行効率は、this と other のうち小さい方のセットのサイズにほぼ依存します(Set が指数時間でアクセスできると仮定した場合)。

例 isDisjointFrom() の使用

完全平方の集合(20 未満)は素数の集合(20 未満)と一致しません。なぜなら、完全平方は定義上、2 つの整数の積に分解できるのに対し、1 は素数とはみなされないからです。

const primes = new Set([2, 3, 5, 7, 11, 13, 17, 19]);
const squares = new Set([1, 4, 9, 16]);
console.log(primes.isDisjointFrom(squares)); // true

完全平方の集合(20 未満)は合成数の集合(20 未満)と互いに素集合ではありません。なぜなら、1以外の完全平方はすべて定義上合成数だからです。

const composites = new Set([4, 6, 8, 9, 10, 12, 14, 15, 16, 18]);
const squares = new Set([1, 4, 9, 16]);
console.log(composites.isDisjointFrom(squares)); // false
仕様書 ブラウザーの互換性 関連情報

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4