File tree 2 files changed +21
-3
lines changed
17 - Sort Without Articles
18 - Adding Up Times with Reduce 2 files changed +21
-3
lines changed Original file line number Diff line number Diff line change 47
47
const clean = ( text ) => text . replace ( / a | t h e | a n / gi, '' )
48
48
const sortedBands = bands . sort ( ( a , b ) => clean ( a ) > clean ( b ) ? 1 : - 1 )
49
49
const list = sortedBands . map ( band => `<li>${ band } </li>` ) . join ( '' )
50
-
51
50
document . querySelector ( '#bands' ) . innerHTML = list
52
-
53
51
</ script >
54
52
55
53
</ body >
Original file line number Diff line number Diff line change 1
- <!DOCTYPE html>
1
+ <!DOCTYPE html>
2
2
< html lang ="en ">
3
3
< head >
4
4
< meta charset ="UTF-8 ">
182
182
</ li >
183
183
184
184
< script >
185
+ const lis = Array . from ( document . querySelectorAll ( 'li' ) )
186
+ const totalSecs = lis . reduce ( ( acc , item ) => {
187
+ const time = item . dataset . time . split ( ':' )
188
+ const mins = Number ( time [ 0 ] )
189
+ const secs = Number ( time [ 1 ] )
190
+
191
+ return acc + ( mins * 60 ) + secs
192
+ } , 0 )
193
+
194
+ console . log ( totalSecs )
195
+ let remainingSecs = totalSecs
196
+ const hours = Math . floor ( remainingSecs / 3600 )
197
+ remainingSecs = remainingSecs % 3600
198
+ const mins = Math . floor ( remainingSecs / 60 )
199
+ remainingSecs = remainingSecs % 60
200
+ const secs = remainingSecs
201
+
202
+ console . log ( 'hours' , hours )
203
+ console . log ( 'minutes' , mins )
204
+ console . log ( 'seconds' , secs )
185
205
</ script >
186
206
</ body >
187
207
</ html >
You can’t perform that action at this time.
0 commit comments