JS30 day18 - Tally String Times with Reduce
作業內容
今天也是主要在練習 JS 的 map / reduce 這兩種方法,要把影片的總時間加總,練習字串轉時間的過程
學到什麼
- JS
- 
nodeList 不能使用 map,只有 array 可以 
 把 nodeList 轉換成 array:Array.from(<nodeList>)或者[...<nodeList>]
- 
如果要使用一個方法把一個陣列的項目全部轉換的話,可以直接使用 `arr.map(function) 
 1 
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11time = "1:56" 
 splited_time = time.split(":").map(parseFloat)
 console.log(splited_time)
 time = "1:56"
 splited_time = time
 .split(":")
 .map((timeCode)=>{
 return parseFloat(timeCode)
 })
 console.log(splited_time)
- 
參考資料:
https://github.com/wesbos/JavaScript30
code 內容:
HTML:
| 1 | <ul class="videos"> | 
JS:
| 1 | const timeNodes = [...document.querySelectorAll('[data-time]')] | 
