File tree Expand file tree Collapse file tree 2 files changed +21
-3
lines changed
17 - Sort Without Articles
18 - Adding Up Times with Reduce Expand file tree Collapse file tree 2 files changed +21
-3
lines changed Original file line number Diff line number Diff line change 4747 const clean = ( text ) => text . replace ( / a | t h e | a n / gi, '' )
4848 const sortedBands = bands . sort ( ( a , b ) => clean ( a ) > clean ( b ) ? 1 : - 1 )
4949 const list = sortedBands . map ( band => `<li>${ band } </li>` ) . join ( '' )
50-
5150 document . querySelector ( '#bands' ) . innerHTML = list
52-
5351</ script >
5452
5553</ body >
Original file line number Diff line number Diff line change 1- <!DOCTYPE html>
1+ <!DOCTYPE html>
22< html lang ="en ">
33< head >
44 < meta charset ="UTF-8 ">
182182 </ li >
183183
184184< 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 )
185205</ script >
186206</ body >
187207</ html >
You can’t perform that action at this time.
0 commit comments