Merge branch 'friendlier-koans'

This commit is contained in:
Tom Marble 2015-06-24 07:58:49 -05:00
commit f30feb25fe
2 changed files with 9 additions and 8 deletions

View File

@ -1,5 +1,6 @@
(ns koans.04-sets (ns koans.04-sets
(:require [koan-engine.core :refer :all])) (:require [koan-engine.core :refer :all]
[clojure.set :as set]))
(meditations (meditations
"You can create a set by converting another collection" "You can create a set by converting another collection"
@ -12,10 +13,10 @@
(= __ (set '(1 1 2 2 3 3 4 4 5 5))) (= __ (set '(1 1 2 2 3 3 4 4 5 5)))
"You can ask clojure for the union of two sets" "You can ask clojure for the union of two sets"
(= __ (clojure.set/union #{1 2 3 4} #{2 3 5})) (= __ (set/union #{1 2 3 4} #{2 3 5}))
"And also the intersection" "And also the intersection"
(= __ (clojure.set/intersection #{1 2 3 4} #{2 3 5})) (= __ (set/intersection #{1 2 3 4} #{2 3 5}))
"But don't forget about the difference" "But don't forget about the difference"
(= __ (clojure.set/difference #{1 2 3 4 5} #{2 3 5}))) (= __ (set/difference #{1 2 3 4 5} #{2 3 5})))

View File

@ -19,20 +19,20 @@
"You can also group by a primary key" "You can also group by a primary key"
(= __ (= __
(group-by :id [{:id 1 :name "Bob"} (group-by :id [{:id 1 :name "Bob"}
{:id 2 :name "Mike"} {:id 2 :name "Jennifer"}
{:id 1 :last-name "Smith"} ])) {:id 1 :last-name "Smith"} ]))
"But be careful when you group by non-required key" "But be careful when you group by non-required key"
(= {"Bob" [{:name "Bob" :id 1}] (= {"Bob" [{:name "Bob" :id 1}]
"Mike" [{:name "Mike" :id 2}] "Jennifer" [{:name "Jennifer" :id 2}]
__ [{:last-name "Smith" :id 1}]} __ [{:last-name "Smith" :id 1}]}
(group-by :name [{:id 1 :name "Bob"} (group-by :name [{:id 1 :name "Bob"}
{:id 2 :name "Mike"} {:id 2 :name "Jennifer"}
{:id 1 :last-name "Smith"}])) {:id 1 :last-name "Smith"}]))
"The true power of group-by comes with custom functions" "The true power of group-by comes with custom functions"
(= __ (= __
(group-by #(if (:bad %) :naughty-list :nice-list) (group-by #(if (:bad %) :naughty-list :nice-list)
[{:name "Jimmy" :bad true} [{:name "Jimmy" :bad true}
{:name "Jack" :bad false} {:name "Anna" :bad false}
{:name "Joe" :bad true}]))) {:name "Joe" :bad true}])))