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/isSupersetOf below:

Set.prototype.isSupersetOf() - JavaScript | MDN

Set.prototype.isSupersetOf()

Baseline 2024

Newly available

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

構文 引数
other

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

返値

other の集合にあるあるすべての要素がこの Set にもあれば true、そうでなければ false です。

解説

数学的な記法では、上位集合は次のように定義されます。

A ⊇ B ⇔ ∀ x ∊ B , x ∊ A A\supseteq B \Leftrightarrow \forall x\in B,\,x\in A

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

メモ: 上位集合の関係は、真の上位集合ではありません。つまり、this と other の中の要素が同じである場合、isSupersetOf() は true を返します。

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

例 isSupersetOf() の使用

偶数(20 未満)の集合は、4 の倍数(20 未満)の集合の上位集合です。

const evens = new Set([2, 4, 6, 8, 10, 12, 14, 16, 18]);
const fours = new Set([4, 8, 12, 16]);
console.log(evens.isSupersetOf(fours)); // true

すべての奇数(20 未満)の集合は、素数(20 未満)の集合の上位集合ではありません。なぜなら、2 は素数ですが、奇数ではないからです。

const primes = new Set([2, 3, 5, 7, 11, 13, 17, 19]);
const odds = new Set([3, 5, 7, 9, 11, 13, 15, 17, 19]);
console.log(odds.isSupersetOf(primes)); // false

同値集合は互いに上位集合です。

const set1 = new Set([1, 2, 3]);
const set2 = new Set([1, 2, 3]);
console.log(set1.isSupersetOf(set2)); // true
console.log(set2.isSupersetOf(set1)); // true
仕様書 ブラウザーの互換性 関連情報

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