iT邦幫忙

2022 iThome 鐵人賽

DAY 5
0

We first establish a few rules between the freelancer and the project manager:

The daily rate is 8 times the hourly rate.
A month has 22 billable days.

The freelancer is offering to apply a discount if the project manager chooses to let the freelancer bill per month, which can come in handy if there is a certain budget the project manager has to work with.

Discounts are modeled as fractional numbers representing percentage, for example 25.0 (25%).

1. Calculate the daily rate given an hourly rate

Implement a function to calculate the daily rate given an hourly rate.

2. Calculate a discounted price

Implement a function to calculate the price after a discount.

3. Calculate the monthly rate, given an hourly rate and a discount

Implement a function to calculate the monthly rate, and apply a discount.
The returned monthly rate should be rounded up (take the ceiling) to the nearest integer.

4. Calculate the number of workdays given a budget, hourly rate and discount

Implement a function that takes a budget, an hourly rate, and a discount, and calculates how many days of work that covers.
The returned number of days should be rounded down (take the floor) to one decimal place.


https://exercism.org/tracks/elixir/exercises/freelancer-rates

defmodule FreelancerRates do
  def daily_rate(hourly_rate) do
    hourly_rate * 8.0
  end

  def apply_discount(before_discount, discount) do
    before_discount - before_discount * discount * 0.01
  end

  def monthly_rate(hourly_rate, discount) do
    ceil(daily_rate(apply_discount(hourly_rate, discount)) * 22)
  end

  def days_in_budget(budget, hourly_rate, discount) do
    Float.floor(budget / daily_rate(apply_discount(hourly_rate, discount)), 1)
  end
end

上一篇
四.Booleans
下一篇
六. Atom & Cond
系列文
戀戀 Elixir30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言