0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

JavaScriptで集合演算

Posted at

「和集合」と「共通部分」と「部分集合か判定」するメソッドです。

// 和集合
function union(a, b) {
    return a.concat(b).filter((e, i, r) => r.indexOf(e) === i);
}

// 共通部分
function intersection(a, b) {
    return a.filter(e => b.includes(e));
}

// 部分集合か判定 (a⊂b なら true を返す)
function isSubset(a, b) {
    return a.every(e => b.includes(e));
}
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?