-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem-5.js
More file actions
24 lines (18 loc) · 744 Bytes
/
problem-5.js
File metadata and controls
24 lines (18 loc) · 744 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
function waitingTime(waitingTimes, serialNumber) {
if (Array.isArray(waitingTimes) &&
typeof serialNumber === 'number' &&
!isNaN(serialNumber) &&
serialNumber > waitingTime.length
) {
const avgTime = waitingTimes.reduce((a, b) => a + b) / waitingTimes.length;
const remindPerson = serialNumber - waitingTimes.length - 1;
return remindPerson * Math.round(avgTime);
} else return 'Invalid Input ';
}
console.log(waitingTime([3, 5, 7, 11, 6], 10))
console.log(waitingTime([13, 2], 6))
console.log(waitingTime([13, 2, 6, 7, 10], 6))
console.log(waitingTime([6], 4))
console.log(waitingTime(7, 10))
console.log(waitingTime("[6,2]", 9))
console.log(waitingTime([7, 8, 3, 4, 5], "9"))