Last active
November 1, 2017 11:27
-
-
Save zacck-zz/ba4ef4d35a0a35371853c2a9ab8bd448 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
defmodule Budget do | |
def sub_totals(expenses) do | |
allCategories = | |
Enum.uniq for %{type: t, cost: _} <- expenses, do: t | |
category_costs = Enum.map(allCategories, fn(x) -> category_total(expenses, x) end) | |
end | |
def category_total(expenses, category) do | |
catExpenses = | |
Enum.sum for %{type: ^category, cost: c} <- expenses, do: c | |
%{category: category, total: catExpenses} | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment