@@ -9,6 +9,8 @@ class Company {
9
9
this . parseLog ( ) ;
10
10
this . guard_most_asleep = this . getGuardMostAsleep ( ) ;
11
11
this . time_when_guard_is_asleep_most = this . guard_most_asleep . getMinuteMostLikelyToBeAsleepDuring ( ) ;
12
+
13
+ this . most_often_asleep_guard_info = this . getGuardWhoSleptMostDuringAnyParticularMinute ( ) ;
12
14
}
13
15
14
16
/**
@@ -81,6 +83,28 @@ class Company {
81
83
return this . guards [ guard_most_asleep . id ] ;
82
84
}
83
85
86
+ getGuardWhoSleptMostDuringAnyParticularMinute ( ) {
87
+ let guards = Object . values ( this . guards ) ;
88
+
89
+ let guard_most_asleep = {
90
+ id : undefined ,
91
+ times : - 1 ,
92
+ minuteAsleepAt : - 1 ,
93
+ } ;
94
+ guards . forEach ( guard => {
95
+ let duple = guard . getMinuteMostLikelyToBeAsleepDuring ( true ) ;
96
+
97
+ let [ minute , times ] = duple ;
98
+ if ( times > guard_most_asleep . times ) {
99
+ guard_most_asleep . times = times ;
100
+ guard_most_asleep . minuteAsleepAt = minute ;
101
+ guard_most_asleep . id = guard . id ;
102
+ }
103
+ } ) ;
104
+
105
+ return guard_most_asleep ;
106
+ }
107
+
84
108
outputPartOne ( ) {
85
109
let guard_most_asleep = this . guard_most_asleep ;
86
110
let time_when_guard_is_asleep_most = this . time_when_guard_is_asleep_most ;
@@ -94,6 +118,19 @@ class Company {
94
118
time_when_guard_is_asleep_most } `
95
119
) ;
96
120
}
121
+
122
+ outputPartTwo ( ) {
123
+ let most_often_asleep_guard = this . most_often_asleep_guard_info ;
124
+ let { minuteAsleepAt } = most_often_asleep_guard ;
125
+
126
+ console . log ( `Guard most asleep is ${ most_often_asleep_guard . id } ` ) ;
127
+ console . log ( `Sleeps the most during minute ${ minuteAsleepAt } ` ) ;
128
+ console . log (
129
+ `ID * minute = ${
130
+ most_often_asleep_guard . id
131
+ } * ${ minuteAsleepAt } = ${ most_often_asleep_guard . id * minuteAsleepAt } `
132
+ ) ;
133
+ }
97
134
}
98
135
99
136
module . exports = Company ;
0 commit comments