Pinterest Board
Challenge 6 - Medium
Description - Part 1
We want to know if new employees do the security training videos. In order to do that we are going to create a function that is going to return the status of the training of an employee. In order to understand the status we have to know that:
- There is going to be a timeline with days
- Thestart_dayis the day that the employee started working.
- Thetrained_dayis the day that the employee did the training.
- Thecheck_dayis the day that we are checking if the employee did the training.
- Thetraining_windowis the amount of days that the employee has to do the training.
How do we know the status? We are going to use these examples:
- The status ispendingif the employee didn't do the training and we are checking inside the training_window.
- The status iscompletedif the employee did the training inside of the training_window.
- The status iscompletedif the employee did the training and we are checking after that day.
- The status isoverdueif the employee didn't do the training and we are checking outside the training_window.
- The status isnot_requiredif we are checking before the start_day.
We are going to have the following data:
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
type Employee = {
start_day: number; // The day the employee started working at the company (in days)
trained_day?: number; // The day the employee was trained (in days), optional
group_id: string; // Indicates the group to which the employee belongs
}
type StatusType = "not_required" | "pending" | "overdue" | "completed";
type Status = {
name: StatusType;
days_overdue: number; // 0 if not overdue
}
// Function signature
function getTrainingStatus(employee: Employee, training_window: number, check_day: number): Status {
}
Description - Part 2
After we have a way to calculate the amount of days of overdue that an employee has, we want to use that in order to know which groups have the most amount of overdue. We are going to be using these data types:
0
1
2
3
4
5
6
7
8
9
10
11
type Group = {
id: string; // Unique identifier for the group
parent_id?: string; // ID of the parent group, if any
child_ids: Array<string>; // IDs of the child groups
}
type Datapoint = {
group_id: string;
num_employees: number;
total_days_overdue: number;
}
Where:
- TheGroup could have other groups as children (only 1 as parent).
- TheDatapointis going to have the total amount of the employees of a group (including the children employees) and the total days overdue of the employees of that group (including the children employees).
Here is the signature of the function that we need to implement to calculate all the datapoints and we are also going to be using this data:
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
const trainingWindow = 10;
const checkDay = 120;
const employees: Employee[] = [
{ start_day: 100, group_id: "a" }, // days_overdue: 10
{ start_day: 105, group_id: "b" }, // days_overdue: 5
{ start_day: 110, group_id: "b" }, // days_overdue: 0
{ start_day: 105, group_id: "c" }, // days_overdue: 5
];
const groupsById: Record<string, Group> = {
a: { id: "a", child_ids: ["b"] },
b: { id: "b", parent_id: "a", child_ids: ["c"] },
c: { id: "c", parent_id: "b", child_ids: [] },
};
// Function signature
function getTotalDaysOverdueByGroups(
employees: Employee[],
groupsById: Record<string, Group>,
trainingWindow: number,
checkDay: number
)
An this is an example of usage and expected result:
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
const result = getTotalDaysOverdueByGroups(
employees,
groupsById,
trainingWindow,
checkDay
);
console.log(result);
/*
Expected Output:
[
{ group_id: "a", num_employees: 4, total_days_overdue: 20 },
{ group_id: "b", num_employees: 3, total_days_overdue: 10 },
{ group_id: "c", num_employees: 1, total_days_overdue: 5 }
]
*/