erlang day 2
This commit is contained in:
parent
f40104937d
commit
4098189e4d
16
erlang/day2.erl
Normal file
16
erlang/day2.erl
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
-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].
|
Loading…
Reference in New Issue
Block a user