1. const seconds = Array.from(document.querySelectorAll('[data-time]'))
    2. .map((node) => node.dataset.time)
    3. .map((timeCode) => {
    4. const [mins, secs] = timeCode.split(':').map(parseFloat);
    5. return (mins * 60) + secs;
    6. })
    7. .reduce((acc, crt) => acc + crt);
    8. let secondsLeft = seconds;
    9. const hours = Math.floor(secondsLeft / 3600);
    10. secondsLeft = secondsLeft % 3600;
    11. const mins = Math.floor(secondsLeft / 60);
    12. secondsLeft = secondsLeft % 60;
    13. console.log(hours, mins, secondsLeft);

    image.png
    image.png

    1. console.log(parseFloat('3.24eee')) // 3.24
    2. console.log(Number('3.24eee')) // NaN
    3. // parseFload()会解析到不是数字为止,然后返回是数字的部分
    4. // Number()是严格模式下的parseFloat
    1. flex: 1 1 calc(33.33% - 20px)
    1. // format JSON code
    2. console.log(JSON.stringify({ alpha: 'A', beta: 'B' }, null, '\t'));
    3. // Result:
    4. // '{
    5. // "alpha": A,
    6. // "beta": B
    7. // }'