Challenge: Add up a list of times stored in list item data attributes. To do this we need to get minutes and seconds separately, store in an array, convert to seconds and add them together.
I’ve done something similar before and took a more long-winded
for loop approach. It turns out that
reduce can be combined to do the same thing.
Array.prototype.map()takes in an array and returns an array
Array.prototype.reduce()takes in an array and returns anything you want
The source is available at github and the live version is here. There’s not a great deal to see but check the console for time totals.