How do i calculate average times in Typescript


I have an object which has the following entry in it:

   numberOfReturns: number = 0;
   returns_explanations: string [] = [];
   departure_time: string = '';
   arrival_time: string = '';

So in departure_time i have the following information:

...
departure_time: 08:15
departure_time: 08:02
departure_time: 09:00
...

I have an array of this whole object which will need to be iterated and i need to get the average departure_times.

let average: Date = null;

for (let i = 0; i < workAccountItem.length; i++) {
    average = moment(average).add(moment('01/01/2021 ' + workAccountItem[i].departure_time));
}

average = average / workAccountItem.length;

This approach won’t work.

Source: JavaSript – Stack Overflow

November 1, 2021
Category : News
Tags: javascript | momentjs | reactjs | typescript

Leave a Reply

Your email address will not be published. Required fields are marked *

Sitemap | Terms | Privacy | Cookies | Advertising

Senior Software Developer

Creator of @LzoMedia I am a backend software developer based in London who likes beautiful code and has an adherence to standards & love's open-source.