Skip to content

Instantly share code, notes, and snippets.

@krishnabhargav
Created March 18, 2014 17:53
Show Gist options
  • Save krishnabhargav/9625553 to your computer and use it in GitHub Desktop.
Save krishnabhargav/9625553 to your computer and use it in GitHub Desktop.
(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