Open chouung opened 8 months ago
주로 배열에서 동일 요소 제거로 사용되는 Set.. 개인적으로는 어서 적용되었으면 하는 기능이네요 !
원문 : Union, intersection, difference, and more are coming to JavaScript Sets
someSet.add
someSet.delete
someSet.has("something")
someSet.forEach
someSet.clear()
setA.union(setB)
const setA = new Set(['setA1', 'setA2', 'something']) const setB = new Set(['setB1', 'setB2', 'something']) const union = setA.union(setB) console.log(union) // Set(5) {'setA1', 'setA2', 'something', 'setB1', 'setB2'}
setA.intersection(setB)
const setA = new Set(['setA1', 'setA2', 'something']) const setB = new Set(['setB1', 'setB2', 'something']) const intersection = setA.intersection(setB) console.log(intersection) // Set(1) {'something'}
setA.difference(other)
const setA = new Set(['setA1', 'setA2', 'something']) const setB = new Set(['setB1', 'setB2', 'something']) const difference = setA.difference(setB) console.log(difference) // Set(2) {'setA1', 'setA2'}
setA.symmetricDifference(other)
const setA = new Set(['setA1', 'setA2', 'something']) const setB = new Set(['setB1', 'setB2', 'something']) const symmetricDifference = setA.symmetricDifference(setB) console.log(symmetricDifference) // Set(4) {'setA1', 'setA2', 'setB1', 'setB2'}
setA.isSubsetOf(other)
const setA = new Set(['setA1', 'setA2', 'something']) const setB = new Set(['setB1', 'setB2', 'something']) const isSubsetOf = setA.isSubsetOf(setB) console.log(isSubsetOf) // false
setA.isSuperssetOf(other)
const setA = new Set(['setA1', 'setA2', 'something']) const setB = new Set(['setB1', 'setB2', 'something']) const isSupersetOf = setA.isSupersetOf(setB) console.log(isSupersetOf) // false
setA.isDisjointFrom(other)
const setA = new Set(['setA1', 'setA2', 'something']) const setB = new Set(['setB1', 'setB2', 'something']) const isDisjointFrom = setA.isDisjointFrom(setB) console.log(isDisjointFrom) // false
님 여기 마크다운 깨졌어용~~ 의도한거면 죄송여~~~
와 추가되는 문법들 진짜 대따좋네요....... 리얼 가끔 저런거 필요하면 구글에다가 list...intersection...subtraction 이랬었는데... 우오오.....
@snaag 의도한것은 맞구요 ^_^... 저도 정말 빨리 적용되었으면 좋겠네요..
javascript Set의 실험적 메서드
원문 : Union, intersection, difference, and more are coming to JavaScript Sets
AS-IS 자바스크립트 Set
someSet.add
someSet.delete
someSet.has("something")
someSet.forEach
someSet.clear()
TO-BE 자바스크립트 Set
setA.union(setB)
setA.intersection(setB)
setA.difference(other)
setA.symmetricDifference(other)
setA.isSubsetOf(other)
setA.isSuperssetOf(other)
setA.isDisjointFrom(other)