-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpredict-average-waiting-time.js
More file actions
35 lines (23 loc) · 936 Bytes
/
predict-average-waiting-time.js
File metadata and controls
35 lines (23 loc) · 936 Bytes
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
// Problem 05: Predict Average Waiting Time
function waitingTime(waitingTimes, serialNumber) {
if (
!Array.isArray(waitingTimes) ||
typeof serialNumber !== "number"
) {
return "Invalid Input";
}
let sum = 0;
for (const number of waitingTimes) {
sum = sum + number;
}
let length = waitingTimes.length;
const averageTime = Math.round(sum / length);
const remainingCandidates = serialNumber - waitingTimes.length - 1;
const time = remainingCandidates * averageTime;
return time;
}
const participants = [10, 5, 8, 12, 15];
// const participants = 10;
const serialNumber = 10;
const time = waitingTime (participants, serialNumber);
console.log(time);