File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed
18 - Adding Up Times with Reduce Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change 182182 </ li >
183183 </ ul >
184184< script >
185+ const timeNodes = document . querySelectorAll ( '[data-time]' ) ;
186+ // convert node list to array
187+ const timeArray = Array . from ( timeNodes ) ;
188+
189+ const seconds = timeArray
190+ . map ( item => item . dataset . time )
191+ . map ( timeCode => {
192+ const [ mins , secs ] = timeCode . split ( ':' ) . map ( parseFloat ) ;
193+ return ( mins * 60 ) + secs ;
194+ } )
195+ . reduce ( ( total , vidSeconds ) => total + vidSeconds ) ;
196+
197+ let secondsLeft = seconds ;
198+ const hours = Math . floor ( secondsLeft / 3600 ) ;
199+ secondsLeft = secondsLeft % 3600 ;
200+
201+ const mins = Math . floor ( secondsLeft / 60 ) ;
202+ secondsLeft = secondsLeft % 60 ;
203+
204+ console . log ( hours , mins , secondsLeft ) ;
205+
206+
185207</ script >
186208</ body >
187209</ html >
You can’t perform that action at this time.
0 commit comments