[Day18] Tally String Times with Reduce

[Day18] Tally String Times with Reduce

需要用到的技巧与练习目标

  1. Array.form
  2. map
  3. split
  4. parseFloat
  5. reduce
  6. Math.floor
  7. %

const timeNodes = Array.from(document.querySelectorAll('[data-time]'))

const seconds = timeNodes
.map(node => node.dataset.time)
.map(timeCode =>{
    const [time, sec] = timeCode.split(':').map(parseFloat);
    return (min * 60) + secs;
})
.reduce((total.vidSecond) => total + vidSeconds);

let secondsLeft = seconds;
const hours = Math.floor(secondsLeft / 3600);
secondsLeft = secondsLeft % 3600;

const mins = Math.floor(secondLeft / 60);
secondsLeft = secondsLeft % 60;

console.log( hours, mins, secondLeft);


<<:  [Day 18]从零开始学习 JS 的连续-30 Days---网路请求POST

>>:  Day 18 网页分析 - Web Application Analysis (Skipfish )

Day 27 让我胆战心惊的微服务 Vol.1

来来来!小笠宏树 老师报名牌有没有在听!看这支,上礼拜老师讲过的,看到没有一直涨一直涨一直涨,你都不...

Day 11 : 子集 Subsets

今天要来解一题以前数学课本第0章都会遇到也很常被我们跳跃式略过的东西。 在看这题之前我们先来了解一个...

Vue 2 & 3 正确使用 TinyMCE (Self Hosted)

前言 由於 CKEditor 的客制化需要仰赖 Webpack,无法在 Vite 的专案上使用 因此...

受信任计算机系统评估标准(TCSEC)

TCSEC定义了评估可信计算系统的标准,该系统包括四个分类。每个分类可以分为几类。B分类的类别(B1...

error CS0246: 找不到类型或命名空间名称 'NewsPaper'

该文件的头加入: using System; 既可以识别了; ...