Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

235
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda