Skip to content

Commit 6c5b4d3

Browse files
committed
tallying string times with reduce complete
1 parent 4fec6e0 commit 6c5b4d3

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,6 @@
181181
Video 58
182182
</li>
183183

184-
<script>
185-
</script>
184+
<script src='js/app.js'></script>
186185
</body>
187186
</html>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const timeNodes = Array.from(document.querySelectorAll('[data-time]'));
2+
const seconds = timeNodes
3+
.map(node => node.dataset.time)
4+
.map(timeCode => {
5+
const [mins, secs] = timeCode.split(':').map(parseFloat);
6+
return mins * 60 + secs;
7+
})
8+
.reduce((total, vidSeconds) => total + vidSeconds);
9+
10+
let secondsLeft = seconds;
11+
const hours = Math.floor(secondsLeft / 3600);
12+
secondsLeft = secondsLeft % 3600;
13+
const mins = Math.floor(secondsLeft / 60);
14+
secondsLeft = secondsLeft % 60;
15+
console.log(hours, mins, secondsLeft);

0 commit comments

Comments
 (0)