hawkeye
hawkeye

Reputation: 35762

How do you sort pairs in a list based on a nested value?

Given the following list in Clojure:

(def pairs '[(2,1),(3,2),(2,4)])

I want to sort these in descending order based on the second item in each pair.

ie I want them to sort into:

[(2,4),(3,2),(2,1)]   

My question is: How do you sort pairs in a list based on a nested value?

Upvotes: 0

Views: 47

Answers (1)

Svante
Svante

Reputation: 51531

Use sort-by:

(sort-by second > pairs)

Upvotes: 4

Related Questions