2019-04-22 02:25:01 +00:00
|
|
|
-module(shop).
|
2019-04-22 14:01:00 +00:00
|
|
|
-export([cost/1, total/1]).
|
2019-04-22 02:25:01 +00:00
|
|
|
|
2019-04-22 14:01:00 +00:00
|
|
|
%% ShoppingList = [{oranges,4},{newspaper,1},{apples,10},{pears,6},{milk,3}]
|
|
|
|
cost (oranges) -> 5;
|
|
|
|
cost (newspaper) -> 8;
|
|
|
|
cost (apples) -> 2;
|
|
|
|
cost (pears) -> 9;
|
|
|
|
cost (milk) -> 7.
|
2019-04-22 02:25:01 +00:00
|
|
|
|
2019-04-22 14:01:00 +00:00
|
|
|
total([]) ->
|
|
|
|
0;
|
|
|
|
total([{Item, Count}|Rest]) ->
|
|
|
|
cost(Item) * Count + total(Rest).
|