Skip to content

Commit c313c41

Browse files
committed
Day 18
1 parent 9ccfa5d commit c313c41

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

18 - Adding Up Times with Reduce/index-FINISHED.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@
192192
return (mins * 60) + secs;
193193
})
194194
.reduce((total, vidSeconds) => total + vidSeconds);
195+
console.log(seconds);
195196

196197
let secondsLeft = seconds;
197198
const hours = Math.floor(secondsLeft / 3600);

18 - Adding Up Times with Reduce/index-START.html

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,21 @@
182182
</li>
183183
</ul>
184184
<script>
185+
const items = Array.from(document.querySelectorAll('.videos li'));
186+
const totalSeconds = items
187+
.map((item) => {
188+
const duration = item.dataset.time;
189+
const [ minutes, seconds ] = duration.split(':').map(parseFloat);
190+
return (60 * minutes) + seconds;
191+
})
192+
.reduce((seconds, cur) => {
193+
return cur + seconds;
194+
}, 0);
195+
const hours = Math.floor(totalSeconds / 60 / 60);
196+
const minutesLeft = Math.floor((totalSeconds - (hours * 60 * 60)) / 60);
197+
const secondsLeft = totalSeconds - (hours * 60 * 60) - (minutesLeft * 60);
198+
// console.log(totalSeconds);
199+
console.log(`${hours}:${minutesLeft}:${secondsLeft}`);
185200
</script>
186201
</body>
187202
</html>

0 commit comments

Comments
 (0)