vanilladocs
vanillapunch.com
API / base/collection/set

base/collection/set

셋 (중복 불허 집합).

Set (a collection without duplicates).

Setextends Object

셋 (중복 불허 집합).

Set (a collection without duplicates).

예제Example합집합과 교집합Union and intersection
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());
생성자constructorconstructor()#0.0.8 부터since 0.0.8소스source

생성.

Constructor.

메서드methodadd(item)#0.0.8 부터since 0.0.8소스source

데이터 추가.

Adds data.

itemT
더할 요소. (이미 있으면 그대로)Item to add. (unchanged if already present)
메서드methodremove(item)#0.0.8 부터since 0.0.8소스source

데이터 제거.

Removes data.

itemT
지울 요소.Item to remove.

반환Returnsboolean 있어서 지웠으면 참.True if it existed and was removed.

메서드methodcontains(item)#0.0.8 부터since 0.0.8소스source

요소 포함 여부 반환.

Returns whether the element is contained.

itemT
찾을 요소.Item to look for.

반환Returnsboolean 있으면 참.True if present.

메서드methodunion(otherSet)#0.0.8 부터since 0.0.8소스source

합집합. (Union)

Union. (Union)

otherSetSet<T>
합칠 다른 셋.Other set to combine.

반환ReturnsSet<T> 두 셋의 요소를 모두 담은 새 셋.New set with all items of both sets.

메서드methodintersection(otherSet)#0.0.8 부터since 0.0.8소스source

교집합. (Intersection)

Intersection. (Intersection)

otherSetSet<T>
견줄 다른 셋.Other set to compare.

반환ReturnsSet<T> 두 셋에 모두 있는 요소만 담은 새 셋.New set with only the items present in both sets.

메서드methoddifference(otherSet)#0.0.8 부터since 0.0.8소스source

차집합. (Difference)

Difference. (Difference)

otherSetSet<T>
뺄 다른 셋.Other set to subtract.

반환ReturnsSet<T> 이 셋에만 있고 다른 셋에는 없는 요소를 담은 새 셋.New set with the items in this set that are not in the other set.

메서드methodsymmetricDifference(otherSet)#0.0.8 부터since 0.0.8소스source

대칭 차집합 (여집합). (Symmetric Difference)

Symmetric difference (complement). (Symmetric Difference)

otherSetSet<T>
견줄 다른 셋.Other set to compare.

반환ReturnsSet<T> 두 셋 가운데 한쪽에만 있는 요소를 담은 새 셋.New set with the items present in only one of the two sets.

메서드methodclear()#0.0.8 부터since 0.0.8소스source

전체 제거.

Removes all.

메서드methodgetCount()#0.0.8 부터since 0.0.8소스source

요소 수 반환.

Returns the element count.

반환Returnsnumber 요소 수.Number of items.

메서드methodtoArray()#0.0.8 부터since 0.0.8소스source

전체 요소 배열 반환.

Returns an array of all elements.

반환ReturnsT[] 넣은 차례의 요소를 담은 새 배열.New array of items in insertion order.