Get to know MDN better
This page was translated from English by the community. Learn more and join the MDN Web Docs community.
Since June 2024, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.
Set 인스턴스의 intersection() 메서드는 집합을 받아서 이 집합과 주어진 집합의 공통 요소를 포함하는 새 집합을 반환합니다.
이 집합과 other 집합에 공통으로 있는 요소를 포함하는 새 Set 객체입니다.
수학적 표기법에서 교집합(intersection)는 다음과 같이 정의됩니다.
A∩B={x∊A∣x∊B}A\cap B = {x\in A\mid x\in B}벤 다이어그램으로 표현하자면 아래와 같습니다.
intersection()은 other 매개변수로 유사 집합 객체를 받습니다. 사용자 코드를 호출하지 않고 this에 저장된 기본 데이터를 직접 검색하기 때문에 실제 Set 인스턴스가 되기 위해 this가 필요합니다. 그런 다음 동작은 this와 other의 크기에 따라 달라집니다.
이 구현으로 인해 intersection()의 효율성은 집합을 선형 이하 시간 내에 액세스할 수 있다고 가정할 때 대부분 this와 other 중 더 작은 집합의 크기에 따라 달라집니다. 반환된 집합의 요소 순서는 this과 other 중 더 작은 집합의 순서와 동일합니다.
다음 예는 홀수 집합(<10)과 완전 제곱 집합(<10) 사이의 교집합을 계산하는 예제입니다. 결과는 완전 제곱인 홀수 집합입니다.
| ECMAScript® 2027 Language Specification # sec-set.prototype.intersection |
Enable JavaScript to view this browser compatibility table.
This page was last modified on 2024년 7월 27일 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.