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

255
Visualizações
Calculate the average distance between two data sets of X and Y (in JS)

I have two databases that I've read from an Excel file, and I converted it to JSON. (my project is in JavaScript)

The first database is a planed track that the pilot should follow, and the second database is the actual track.

I need to calculate the average distance between the tracks. The problem is that the tracks don't have the same amount of points on them and so I don't know what distance should I calculate.

I printed the databases with chart.js and they are looking like this: enter image description here

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You could use map() to calculat the differences, reduce() to get the total and then divide by the length.

const distancesA = [17, 54, 87, 101, 120];
const distancesB = [12, 57, 82, 100, 125];

const averageDistance = distancesA.map((d, i) => d - distancesB[i]).reduce((acc, val) => acc + val, 0) / distancesA.length;

console.log(averageDistance)

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