Clojure从zipmap获得最高价值 [英] Clojure getting highest value from zipmap

查看:49
本文介绍了Clojure从zipmap获得最高价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我在这里有了建议的邮政编码地图,它可以完美地工作.如您所见,我已经加载了数据.

So I've got my proposed zip map here and it works perfectly. As you can see I've got the data loading.

那是完美的副本中的样子.这是地图

That is what it looks like in the repl which is perfect. And right here is the map

:Year 2020, :Day 27, :January 59, :February 38
:Year 2020, :Day 28, :January 41, :February 57
:Year 2020, :Day 29, :January 56, :February 51
:Year 2020, :Day 31, :January 94, :February -999
:Year 2020, :Day 30, :January 76, :February -999 

(map [:Day :Month

请记住,这只是我完成的代码的一部分.您如何建议我找到一月份的价值最高的一天?最高,我的意思是几个月后的数字

Bear in mind this is just a snippet of the code I've done. How would you propose I find the highest value day in January? And by highest I mean by the number next to the months

(into(sorted-map-by >(fn [:January]))Ha) 

我尝试失败,"Ha"最后只是初始化zipmap并使用io/reader读取文件的函数的名称

I tried this to no success, The "Ha" at the end is just the name of the function where I am initialising the zipmap and using io/reader to read the file

推荐答案

我会使用 max-键减少:

(def data [{:Year 2020, :Day 27, :January 59, :February 38}
           {:Year 2020, :Day 28, :January 41, :February 57}
           {:Year 2020, :Day 29, :January 56, :February 51}
           {:Year 2020, :Day 31, :January 94, :February -999}
           {:Year 2020, :Day 30, :January 76, :February -999}])

(reduce (partial max-key :January) data)
;; => {:Year 2020, :Day 31, :January 94, :February -999}

(:Day (reduce (partial max-key :January) data))
;; => 31

这篇关于Clojure从zipmap获得最高价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆