Created
March 18, 2014 17:53
-
-
Save krishnabhargav/9625553 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
(defn get-average-height | |
[people] | |
(let [people-with-height (filter #(contains? % :height) people) | |
heights (map #(:height %1) people-with-height) | |
total (count people-with-height)] | |
(/ (reduce + heights) total))) | |
(defn get-average-height2 | |
[people] | |
(let [people-with-heights (filter #(contains? % :height) people)] | |
(/ (reduce + (map #(:height %1) people-with-heights)) | |
(count people-with-heights)))) | |
(get-average-height2 [{"name" "Mary" :height 160} | |
{"name" "Isla" :height 80} | |
{"name" "Sam"}]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment