[javascript] 모든 배열에서 동시에 존재하는 값 찾기

const arrays = [
      [0, 5, 12, 13, 21, 23, 25, 26, 27, 28, 31, 32, 33, 34, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 55, 56, 57, 58, 63, 64, 66, 67, 68, 69],
      [0, 6, 7, 11, 12, 13, 21, 22, 23, 25, 26, 27, 28, 30, 31, 32, 33, 34, 42, 45, 46, 47, 48, 49, 50, 51, 52, 54, 55, 56, 57, 58, 59, 60, 61, 63, 64],
      [0, 5, 12, 13, 16, 21, 23, 24, 25, 26, 31, 32, 33, 34, 42, 43, 44, 45, 46, 47, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 63, 64],
      [0, 5, 12, 21, 22, 23, 25, 26, 31, 32, 33, 34, 42, 43, 44, 45, 47, 50, 51, 55, 56, 57, 58, 63, 64],
      [0, 2, 5, 12, 13, 15, 16, 17, 18, 19, 21, 23, 24, 25, 26, 29, 31, 32, 33, 34, 38, 40, 42, 44, 45, 46, 47, 48, 49, 50, 51, 52, 54, 55, 56, 57, 58, 59, 60, 61, 63, 64, 66, 67],
      [0, 5, 17, 21, 23, 24, 25, 26, 31, 32, 33, 34, 40, 41, 42, 45, 46, 47, 50, 51, 53, 56, 60, 61, 63, 66, 67]
];

const commonValues = arrays[0].filter(value =>
      arrays.every(array => array.includes(value))
);

console.log(commonValues)

Leave a Comment