Last active
April 6, 2017 19:21
-
-
Save iain17/ec227b12ad1f0bdd234d0604adc04509 to your computer and use it in GitHub Desktop.
Assignment: Consider a shopping list that looks like [{item quantity price}, ...]. Write a list comprehension that builds a list of items of the form [{item total_price}, ...], where total_price is quantity times price.
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
[{"Beer", 2.50, 8}, {"Snacks", 1.99, 4}] |
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
-module(total_price). | |
-export([calc_bill/1]). | |
%Assignment: Consider a shopping list that looks like [{item quantity price}, ...]. Write a list comprehension that builds a list of items of the form [{item total_price}, ...], where total_price is quantity times price. | |
% Using a pipe, go through each part of the list and do the calculation. Then return this. | |
calc_bill(Bill) -> | |
[{Item, Quantity * Price} || {Item, Quantity, Price} <- Bill]. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment