[Vuejs]-Find the sum of time objects VueJS

0๐Ÿ‘

    let timeObjects = ["03:57:58", "01:35:44", "01:01:01"];

    let aggregate = timeObjects.map(t => t.split(':')).reduce((arr,item,index)=>{
        arr[0]+= parseInt(item[0]);
        arr[1]+= parseInt(item[1]);
        arr[2]+= parseInt(item[2]);
        if(arr[2]>60)
        {
            arr[1]++;
            arr[2]%=60;
        }

        if(arr[1]>60)
        {
            arr[0]++;
            arr[1]%=60;
        }
        return arr;
    },[0,0,0])
    .join(':')

Leave a comment