File tree Expand file tree Collapse file tree 1 file changed +13
-17
lines changed
Chapter04/Activity4.01/src/packt-clj Expand file tree Collapse file tree 1 file changed +13
-17
lines changed Original file line number Diff line number Diff line change 11(ns packt-clj.game-values )
22
3-
43(def game-users
54 [{:id 9342
65 :username " speedy"
6362 :experience-level 8
6463 :status :active }])
6564
66-
6765(defn max-value-by-status [field status users]
68- (->>
69- users
70- ; ; step 1: use filter to only keep users who
71- ; ; have the status we are looking for
72- (filter #(= (:status %) status))
73- ; ; step 2: field is a keyword, so we can use it as
74- ; ; a function when calling map.
75- (map field)
76- ; ; step 3: use the apply max pattern, with a default
77- (apply max 0 )))
66+ (->> users
67+ ; ; step 1: use filter to only keep users who
68+ ; ; have the status we are looking for
69+ (filter #(= (:status %) status))
70+ ; ; step 2: field is a keyword, so we can use it as
71+ ; ; a function when calling map.
72+ (map field)
73+ ; ; step 3: use the apply max pattern, with a default
74+ (apply max 0 )))
7875
7976(defn min-value-by-status [field status users]
80- (->>
81- users
82- (filter #(= (:status %) status))
83- (map field)
84- (apply min 0 )))
77+ (->> users
78+ (filter #(= (:status %) status))
79+ (map field)
80+ (apply min))) ; ; do not use a default, (min '()) returns nil
You can’t perform that action at this time.
0 commit comments