Skip to content

Latest commit

 

History

History
30 lines (22 loc) · 797 Bytes

exercise-find-the-average.md

File metadata and controls

30 lines (22 loc) · 797 Bytes

EXERCISE: Find the average energy plan

Note::Find the average cost of energy plans

Write a function that takes the yearly cost of energy plans from several providers

The function should return the average of cost of those energy plans.

()
(defn average-plan-cost [energy-plan-costs]
  (/ (reduce + energy-plan-costs) (count energy-plan-costs)))

(average-plan-cost [10 12])
;; => 11

(average-plan-cost [250 190 270 180 220 240 200 210 220 230])
;; => 221

Hint::

The functions reduce and count should help you solve this challenge

Using a vector of numbers to represent the energy plan costs is probably the simplest approach