Created
January 19, 2019 17:03
-
-
Save orb/9606d26154c509bf46b46e730236ac1b to your computer and use it in GitHub Desktop.
compare team data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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