-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAngryProfessor.js
37 lines (25 loc) · 1.2 KB
/
AngryProfessor.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
// Angry Professor
// A Discrete Mathematics professor has a class of students. Frustrated with their lack of discipline,
// the professor decides to cancel class if fewer than some number of students are present when class starts. Arrival times go from on time (arrivalTime <= 0) to arrived late (arrivalTime > 0).
// Given the arrival time of each student and a threshhold number of attendees, determine if the class is cancelled
// Note: Non-positive arrival times (a[i] < 0) indicate the student arrived early or on time; positive arrival times (a[i] > 0) indicate the student arrived a[i] minutes late.
// Function Description
// Complete the angryProfessor function in the editor below. It must return YES if class is cancelled, or NO otherwise.
// angryProfessor has the following parameter(s):
// int k: the threshold number of students
// int a[n]: the arrival times of the students
// Returns
// string: either YES or NO
function angryProfessor(k, a) {
let onTime = []
a.forEach(time => {
if(time <= 0){
onTime.push(time)
}
})
if(onTime.length >= k){
return "NO"
}else{
return "YES"
}
}