Skip to content

Commit afba06f

Browse files
committed
Sorting agents by job type
1 parent 9716db8 commit afba06f

File tree

1 file changed

+40
-2
lines changed
  • programming_challenges/playground/jobs

1 file changed

+40
-2
lines changed

programming_challenges/playground/jobs/job.clj

+40-2
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,15 @@
1515
:secondary_skillset ["bills-questions"]}])
1616
;; -- end of jobs and agents definition --
1717

18+
;; -- sorting by urgency --
1819
(defn sorted-jobs
1920
[jobs]
2021
(sort-by (complement :urgent) jobs))
2122

2223
(sorted-jobs jobs)
24+
;; -- end of sorting by urgency --
2325

24-
;; filtering by skillsets
25-
26+
;; -- filtering by skillsets --
2627
(def first-job (first jobs))
2728
(def second-job (second jobs))
2829

@@ -35,9 +36,46 @@
3536
(defn filter-by-skillset
3637
[current-job agents]
3738
(filter #(by-skillset current-job %) agents))
39+
;; -- end of filtering by skillsets --
3840

3941
;; -- examples of function use --
4042
(filter-by-skillset first-job agents)
4143
(filter-by-skillset second-job agents)
4244
(filter-by-skillset second-job (conj agents {:id "123" :name "Mr. Nothing" :primary_skillset ["nothing-other"] :secondary_skillset ["nothing"]}))
4345
;; -- end of examples of function use --
46+
47+
;; -- sorting by job type --
48+
(defn find-agent-by-id
49+
[id]
50+
(first
51+
(filter
52+
(fn [agent] (= id (:id agent)))
53+
agents)))
54+
55+
(defn agent-has-job-type-as-skillset?
56+
[job-type agent]
57+
(if (some #{job-type} (:primary_skillset agent))
58+
0
59+
1))
60+
61+
(defn has-skillset-and-id-pair
62+
[job-type agent]
63+
[(agent-has-job-type-as-skillset? job-type agent)
64+
(:id agent)])
65+
66+
(defn build-agent-by-id
67+
[agent-id]
68+
{:id agent-id
69+
:name (:name (find-agent-by-id agent-id))
70+
:primary_skillset (:primary_skillset (find-agent-by-id agent-id))
71+
:secondary_skillset (:secondary_skillset (find-agent-by-id agent-id))})
72+
73+
(defn rebuild-agent
74+
[agent]
75+
(let [agent-id (second agent)]
76+
(build-agent-by-id agent-id)))
77+
78+
(->> agents
79+
(map (partial has-skillset-and-id-pair (:type second-job)))
80+
(sort-by first)
81+
(map rebuild-agent))

0 commit comments

Comments
 (0)