Slide 30
Slide 30 text
*NNVUBCMF4FU
ෆมͷॏෳͳ͠ू߹
// init with Array
const s1 = Set([1, 2, 3]) // => Set [1, 2, 3]
// #has(value) to check value presence
// NOTE: Set#has is potentially faster O(logN) than Array#includes O(N)
s1.has(2) // => true
// Set#add(value) to add new value
s1.add(3) // => Set [1, 2, 3] <- duplicated, no change
const s2 = s1.add(4) // => Set [1, 2, 3, 4]
// Set#delete(value) to delete value from set
const s3 = s2.delete(1) // => Set [2, 3, 4]
// set-theoretical operations
s1.intersect(s3) // => Set [2, 3] <- S1 ∩ S3
s1.union(s2) // => Set [1, 2, 3, 4] <- S1 ∪ S3
s1.subtract(s3) // => Set [1] <- S1 \ S3