Permalink
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
29 lines (20 sloc) 571 Bytes
class Set
constructor: (arr) ->
arr ?= []
@set = {}
@set[item] = true for item in arr
@arr = (item for item of @set)
asArray: ->
@arr
toString: () ->
"{ #{ @asArray().join ', ' } }"
intersection: (otherSet) ->
items = (item for item of @set when item of otherSet.set)
new Set(items)
union: (otherSet) ->
new Set(@asArray().concat otherSet.asArray())
subtract: (otherSet) ->
items = (item for item of @set when not (item of otherSet.set))
new Set(items)
length: -> @asArray().length
module.exports = Set