Skip to content

Commit 90f14d0

Browse files
author
Justin Ramel
committed
reduce time
1 parent a0c83c3 commit 90f14d0

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

17 - Sort Without Articles/index-START.html

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,7 @@
4747
const clean = (text) => text.replace(/a |the |an /gi, '')
4848
const sortedBands = bands.sort((a,b) => clean(a) > clean(b) ? 1 : -1)
4949
const list = sortedBands.map(band => `<li>${band}</li>`).join('')
50-
5150
document.querySelector('#bands').innerHTML = list
52-
5351
</script>
5452

5553
</body>

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!DOCTYPE html>
1+
<!DOCTYPE html>
22
<html lang="en">
33
<head>
44
<meta charset="UTF-8">
@@ -182,6 +182,26 @@
182182
</li>
183183

184184
<script>
185+
const lis = Array.from(document.querySelectorAll('li'))
186+
const totalSecs = lis.reduce((acc, item) => {
187+
const time = item.dataset.time.split(':')
188+
const mins = Number(time[0])
189+
const secs = Number(time[1])
190+
191+
return acc + (mins * 60) + secs
192+
}, 0)
193+
194+
console.log(totalSecs)
195+
let remainingSecs = totalSecs
196+
const hours = Math.floor(remainingSecs / 3600)
197+
remainingSecs = remainingSecs % 3600
198+
const mins = Math.floor(remainingSecs / 60)
199+
remainingSecs = remainingSecs % 60
200+
const secs = remainingSecs
201+
202+
console.log('hours', hours)
203+
console.log('minutes', mins)
204+
console.log('seconds', secs)
185205
</script>
186206
</body>
187207
</html>

0 commit comments

Comments
 (0)