# base/collection/set (vanilla.js 0.4.0)

> https://vanillapunch.com/docs/vanilla.js/0.4.0/api/base/collection/set/

셋 (중복 불허 집합).

## Set extends Object

셋 (중복 불허 집합).

예제: 합집합과 교집합

```js
import { Set } from "./build/vanilla.js";

const left = new Set();
left.add(1);
left.add(2);
left.add(2);
const right = new Set();
right.add(2);
right.add(3);
console.log(left.getCount(), left.union(right).toArray(), left.intersection(right).toArray(), left.difference(right).toArray());
```

- `constructor()` (constructor, since 0.0.8): 생성.
- `add(item)` (method, since 0.0.8): 데이터 추가.
  - `item` T: 더할 요소. (이미 있으면 그대로)
- `remove(item)` (method, since 0.0.8): 데이터 제거.
  - `item` T: 지울 요소.
  - returns boolean: 있어서 지웠으면 참.
- `contains(item)` (method, since 0.0.8): 요소 포함 여부 반환.
  - `item` T: 찾을 요소.
  - returns boolean: 있으면 참.
- `union(otherSet)` (method, since 0.0.8): 합집합. (Union)
  - `otherSet` Set<T>: 합칠 다른 셋.
  - returns Set<T>: 두 셋의 요소를 모두 담은 새 셋.
- `intersection(otherSet)` (method, since 0.0.8): 교집합. (Intersection)
  - `otherSet` Set<T>: 견줄 다른 셋.
  - returns Set<T>: 두 셋에 모두 있는 요소만 담은 새 셋.
- `difference(otherSet)` (method, since 0.0.8): 차집합. (Difference)
  - `otherSet` Set<T>: 뺄 다른 셋.
  - returns Set<T>: 이 셋에만 있고 다른 셋에는 없는 요소를 담은 새 셋.
- `symmetricDifference(otherSet)` (method, since 0.0.8): 대칭 차집합 (여집합). (Symmetric Difference)
  - `otherSet` Set<T>: 견줄 다른 셋.
  - returns Set<T>: 두 셋 가운데 한쪽에만 있는 요소를 담은 새 셋.
- `clear()` (method, since 0.0.8): 전체 제거.
- `getCount()` (method, since 0.0.8): 요소 수 반환.
  - returns number: 요소 수.
- `toArray()` (method, since 0.0.8): 전체 요소 배열 반환.
  - returns T[]: 넣은 차례의 요소를 담은 새 배열.
