-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfreelancer-rates.js
64 lines (56 loc) · 2.15 KB
/
freelancer-rates.js
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
// @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 ratePerHour * 8;
}
/**
* Calculates the number of days in a budget, rounded down
*
* @param {number} budget: the total budget
* @param {number} ratePerHour: the rate per hour
* @returns {number} the number of days
*/
export function daysInBudget(budget, ratePerHour) {
return Math.floor(budget / (ratePerHour * 8));
}
/**
* Calculates the discounted rate for large projects, rounded up
*
* @param {number} ratePerHour
* @param {number} numDays: number of days the project spans
* @param {number} discount: for example 20% written as 0.2
* @returns {number} the rounded up discounted rate
*/
export function calculateMonths(numDays) {
console.log(Math.floor((numDays / 22) * 22))
return Math.floor(numDays / 22) * 22}
export function calculateDiscount(discount) {
return 1 - discount}
export function priceWithMonthlyDiscount(ratePerHour, numDays, discount) {
console.log((numDays - calculateMonths(numDays)) * dayRate(ratePerHour))
return Math.ceil((calculateMonths(numDays) * dayRate(ratePerHour)) * calculateDiscount(discount) +
((numDays - calculateMonths(numDays)) * dayRate(ratePerHour)))
}