Created
October 17, 2020 09:07
-
-
Save ThaddeusJiang/9e487d4d5c1944e94fb136f1b7a21ad2 to your computer and use it in GitHub Desktop.
Calculate total price in Elixir, see https://twitter.com/ThaddeusJiang/status/1317388280724287488?s=20
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 Jstore do | |
@moduledoc """ | |
Documentation for `Jstore`. | |
""" | |
@doc """ | |
Hello world. | |
## Examples | |
iex> Jstore.total_price(:china_jzh, 100) | |
100 | |
""" | |
def total_price(:china_jzh, price) do | |
if price >= 100 do | |
price | |
else | |
price + price * 0.03 | |
end | |
end | |
def total_price(:china_others, price) do | |
price + price * 0.03 | |
end | |
def total_price(:australia, price) do | |
price + price * 0.05 + price * 0.1 | |
end | |
def total_price(:others_country, price) do | |
price + price * 0.07 + price * 0.17 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment