File tree Expand file tree Collapse file tree 2 files changed +17
-1
lines changed
18 - Adding Up Times with Reduce Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Original file line number Diff line number Diff line change 182182 </ li >
183183
184184< script >
185+ // ugly way:
186+ // var totalSeconds = 0;
187+ // [...document.querySelectorAll('[data-time]')].forEach(ele => {
188+ // var arr = ele.getAttribute('data-time').split(':');
189+ // totalSeconds += Number((arr[0])) * 60 + Number((arr[1]));
190+ // })
191+
192+ // elegant way:
193+ var totalSeconds = [ ...document . querySelectorAll ( '[data-time]' ) ]
194+ . map ( ele => ele . getAttribute ( 'data-time' ) . split ( ':' ) )
195+ . map ( arr => Number ( ( arr [ 0 ] ) ) * 60 + Number ( ( arr [ 1 ] ) ) )
196+ . reduce ( ( prev , current ) => prev += current , 0 ) ;
197+
198+ console . log ( `%c Video length: ${ parseInt ( totalSeconds / 3600 ) } hours,
199+ ${ parseInt ( ( totalSeconds % 3600 ) / 60 ) } minutes,
200+ ${ parseInt ( ( totalSeconds % 3600 ) % 60 ) } seconds.` , 'font-size: 20px;color: red' )
185201</ script >
186202</ body >
187203</ html >
Original file line number Diff line number Diff line change 212115 . [x] ~~ LocalStorage~~
222216 . [x] ~~ Mouse Move Shadow~~
232317 . [x] ~~ Sort Without Articles~~
24- 18 . [ ] Adding Up Times with Reduce
24+ 18 . [x] ~~ Adding Up Times with Reduce~~
252519 . [ ] Webcam Fun
262620 . [ ] Speech Detection
272721 . [ ] Geolocation
You can’t perform that action at this time.
0 commit comments