clojure-koans/src/koans/sets.clj

20 lines
511 B
Clojure
Raw Normal View History

2010-02-06 23:43:06 +00:00
(meditations
"You can create a set in two ways"
2010-07-26 23:20:42 +00:00
(= #{} (set nil))
2010-02-06 23:43:06 +00:00
"They are another important data structure in clojure"
(= __ (.size #{}))
2010-07-26 23:20:42 +00:00
"Remember that a set is a 'set'"
(= __ (set '(1 1 2 2 3 3 4 4 5 5)))
2010-02-06 23:43:06 +00:00
2010-07-26 23:20:42 +00:00
"You can ask clojure for the union of two sets"
(= __ (clojure.set/union #{1 2 3 4} #{2 3 5}))
2010-02-06 23:43:06 +00:00
2010-07-26 23:20:42 +00:00
"And also the intersection"
(= __ (clojure.set/intersection #{1 2 3 4} #{2 3 5}))
2010-02-06 23:43:06 +00:00
2010-07-26 23:20:42 +00:00
"But don't forget about the difference"
(= __ (clojure.set/difference #{1 2 3 4 5} #{2 3 5})))
2010-02-06 23:43:06 +00:00