Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

228
Views
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.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

In your main type interface, it looks like you have an extra space between string and [] for returns_explanations -- if you're defining a prop as having a type array of strings, it should be string[] with no space. For your type definition for average, you can also set it to being either Date or null like so, average: Date | null, which will prevent type errors when no date is present yet.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!