Clojure: finding the minimum value in vectors of vectors

I have a sequence with a structure like this:

(def date-sequence [[20101121 10] [20101120 9] [20101119 8] [20101118 7]])

This seems like a nested vector for me, but I'm not sure what to name it. Inside each "embedded vector" are two elements: a date element and a value element: [20101121 10]. Let me call the date element 20101121 x and the value element 10 y.

I want to know how to find the date (x) and value (y) that correspond to the minimum value (y) over the entire sequence of dates.

+3
source share
1 answer

Try the following:

user=> (apply min-key second date-sequence)
[20101118 7]

Then you can use firstand secondto get the date and value.

+8

Source: https://habr.com/ru/post/1776150/


All Articles