-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfreelancer-rates.mjs
70 lines (64 loc) · 2.19 KB
/
freelancer-rates.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// @ts-check
//
// ☝🏽 The line above enables type checking for this file. Various IDEs interpret
// the @ts-check directive. It will give you helpful autocompletion on the web
// and supported IDEs when implementing this exercise. You don't need to
// understand types, JSDoc, or TypeScript in order to complete this JavaScript
// exercise, and can completely ignore this comment block and directive.
// 👋🏽 Hi again!
//
// A quick reminder about exercise stubs:
//
// 💡 You're allowed to completely clear any stub before you get started. Often
// we recommend using the stub, because they are already set-up correctly to
// work with the tests, which you can find in ./freelancer-rates.spec.js.
//
// 💡 You don't need to write JSDoc comment blocks yourself; it is not expected
// in idiomatic JavaScript, but some companies and style-guides do enforce them.
//
// Get those rates calculated!
/**
* The day rate, given a rate per hour
*
* @param {number} ratePerHour
* @returns {number} the rate per day
*/
export function dayRate(ratePerHour) {
return 8 * ratePerHour;
}
function monthRateWithoutDiscount(ratePerHour) {
return 22 * dayRate(ratePerHour);
}
/**
* Calculates the rate per month
*
* @param {number} ratePerHour
* @param {number} discount for example 20% written as 0.2
* @returns {number} the rounded up monthly rate
*/
export function monthRate(ratePerHour, discount) {
let discountedRate = applyDiscount(monthRateWithoutDiscount(ratePerHour), discount);
return Math.ceil(discountedRate);
}
/**
* Calculates the number of days in a budget, rounded down
*
* @param {number} budget the total budget
* @param {number} ratePerHour the rate per hour
* @param {number} discount to apply, example 20% written as 0.2
* @returns {number} the number of days
*/
export function daysInBudget(budget, ratePerHour, discount) {
let totalDays = budget / dayRate(applyDiscount(ratePerHour,discount));
return Math.floor(totalDays);
}
/**
* Applies a discount to the value
*
* @param {number} value
* @param {number} percentage for example 20% written as 0.2
* @returns {number} the discounted value
*/
function applyDiscount(value, percentage) {
return value - (value * percentage);
}