File tree Expand file tree Collapse file tree 3 files changed +23
-208
lines changed
18 - Adding Up Times with Reduce Expand file tree Collapse file tree 3 files changed +23
-208
lines changed Original file line number Diff line number Diff line change 1+ const timeNodes = Array . from ( document . querySelectorAll ( '[data-time]' ) ) ;
2+
3+
4+ //try putting this all in one reduce;
5+
6+
7+ const seconds = timeNodes
8+ . map ( node => node . dataset . time )
9+ . map ( timeCode => {
10+ const [ mins , secs ] = timeCode . split ( ':' ) . map ( parseFloat ) ;
11+ return ( mins * 60 ) + secs ;
12+ } )
13+ . reduce ( ( total , vidSeconds ) => total + vidSeconds )
14+
15+ let secondsLeft = seconds ;
16+ const hours = Math . floor ( secondsLeft / 3600 ) ;
17+ secondsLeft = secondsLeft % 3600 ;
18+
19+ const mins = Math . floor ( secondsLeft / 60 ) ;
20+ secondsLeft = secondsLeft % 60 ;
21+
22+ console . log ( hours , mins , secondsLeft ) ;
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 181181 Video 58
182182 </ li >
183183
184- < script >
184+ < script src =" adding.js " >
185185</ script >
186186</ body >
187187</ html >
You can’t perform that action at this time.
0 commit comments