17 lines
463 B
Erlang
17 lines
463 B
Erlang
-module(day2).
|
|
-export([get_key/2]).
|
|
-export([calc_total/1]).
|
|
|
|
% day2:get_key(test, [{test, "abc"}, {hage, "buddne"}]).
|
|
% get_key(Key, Array) -> [V || {K, V} <- Array, K == Key].
|
|
get_key(_, []) -> notfound;
|
|
get_key(Key, [{K, V} | T]) ->
|
|
if K == Key ->
|
|
V;
|
|
true ->
|
|
get_key(Key, T)
|
|
end.
|
|
|
|
% day2:calc_total([{"Bohnen", 4, 0.20}, {"Erbsen", 3, 0.15}, {"Linsen", 7, 0.30}]).
|
|
calc_total(Array) -> [{Item, Quantity * Price} || {Item, Quantity, Price} <- Array].
|