Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

237
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda