LoginSignup
0
1

【Javascript/Node.js】ある配列が別の配列の部分集合であることを判定する

Last updated at Posted at 2018-08-26

「ある配列の要素すべてがもうひとつの配列に含まれる」と考える。

const superset = [10, 20, 30, 40, 100];
const arrayA = [10, 20, 40];
const arrayB = [10, 20, 50];

const isSubset = array => array.every(x => superset.includes(x));

console.log(isSubset(arrayA)); // true
console.log(isSubset(arrayB)); // false
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