compare team data
(ns sort-compare.core) | |
(def team-data | |
[{:team-id 1 | |
:total-pts 7 | |
:matches [{:schedule-id 1 :opp-team-id 2 :opp-team-pts 6 :team-points 3} | |
{:schedule-id 2 :opp-team-id 3 :opp-team-pts 6 :team-points 4}]} | |
{:team-id 2 | |
:total-pts 7 | |
:matches [{:schedule-id 1 :opp-team-id 1 :opp-team-pts 3 :team-points 6} | |
{:schedule-id 3 :opp-team-id 3 :opp-team-pts 6 :team-points 1}]} | |
{:team-id 3 | |
:total-pts 12 | |
:matches [{:schedule-id 2 :opp-team-id 1 :opp-team-pts 4 :team-points 6} | |
{:schedule-id 3 :opp-team-id 2 :opp-team-pts 1 :team-points 6}]}]) | |
(defn compare-points-winner-first [team1 team2] | |
(compare (:total-pts team2) (:total-pts team1))) | |
(defn head-to-head-match [team1 team2] | |
"returns the head to head match between team1 and team2" | |
(first (filter (fn [match] | |
(= (:team-id team2) | |
(:opp-team-id match))) | |
(:matches team1)))) | |
(defn compare-head-to-head-winner-first [team1 team2] | |
(if-let [match (head-to-head-match team1 team2)] | |
(compare (:opp-team-pts match) (:team-points match)) | |
0)) | |
(defn match-comparator [team1 team2] | |
(let [compare-points (compare-points-winner-first team1 team2)] | |
(if (= 0 compare-points) | |
(compare-head-to-head-winner-first team1 team2) | |
compare-points))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment