Skip to content

Commit a436254

Browse files
author
Sergey Royz
committed
18
1 parent ae17362 commit a436254

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,11 +177,29 @@
177177
<li data-time="1:56">
178178
Video 57
179179
</li>
180-
<li data-time="4:04">
180+
<li data-time="4:01">
181181
Video 58
182182
</li>
183183
</ul>
184184
<script>
185+
186+
const items = Array.from(document.querySelectorAll("[data-time]"));
187+
let totalSeconds = items
188+
.map(item => item.dataset.time)
189+
.map(item => {
190+
const [m, s] = item.split(":").map(parseFloat);
191+
return m * 60 + s;
192+
})
193+
.reduce((total, seconds) => total + seconds);
194+
195+
const hrs = Math.floor(totalSeconds / 3600);
196+
totalSeconds = totalSeconds % 3600;
197+
const mins = Math.floor(totalSeconds / 60);
198+
totalSeconds = totalSeconds % 60;
199+
const secs = totalSeconds;
200+
201+
console.log(`${hrs}hrs ${mins}mins ${secs}secs`);
202+
185203
</script>
186204
</body>
187205
</html>

0 commit comments

Comments
 (0)