Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting a vector of largest keys in vector of maps

I have a vector of maps, which looks like this:

(def game-vec [{:game 1 :start 123456}
        {:game 2 :start 523456}
        {:game 3 :start 173456}
        {:game 1 :start 123456}
        {:game 1 :start 523456}
        {:game 2 :start 128456}
        {:game 3 :start 123256}])

I'd like to take the biggest :start time for each :game. What's the best way to do this?

like image 452
KushalP Avatar asked Dec 09 '22 06:12

KushalP


1 Answers

Here is yet another solution

user=> (map #(apply max-key :start %) 
            (vals (group-by :game game-vec)))
({:game 1, :start 523456} 
 {:game 2, :start 523456} 
 {:game 3, :start 173456})
like image 199
Jonas Avatar answered Jan 19 '23 05:01

Jonas