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

156
Visualizações
Merge different Arrays and Calculate Average price Javascript

I am trying to calculate and create an Array with Average Prices for different stocks.

For every stock, I have the Data in this format:

{
  prices: [
    [
      1634304009628,
      0.7118076876774715
    ],
    [
      1634307586874,
      0.7063647246346818
    ],
    [
      1634311139365,
      0.7049706990925925
    ],
    [
      1634313858611,
      0.7085543691926037
    ],
    [
      1634318343009,
      0.7057442983161784
    ]
  ]
}

For every stock API call I get the data like how I posted above, it has 2 values timestamp and the second one is the price. Now let's say I want the average trend for 5 stocks I will get the data in 5 different arrays and I just want to somehow make an average out of those 5 arrays in one to find the trend.

For the final result, I want the Array to be in the same format just with the calculated average altogether (the goal is to identify the trend direction).

What would be the best way to do that? I am Using React

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

0

first create and array of prices only and then using reduce you can just do this:

let myObj = {
  prices: [
    [
      1634304009628,
      0.7118076876774715
    ],
    [
      1634307586874,
      0.7063647246346818
    ],
    [
      1634311139365,
        0.7049706990925925
    ],
    [
      1634313858611,
      0.7085543691926037
    ],
    [
      1634318343009,
      0.7057442983161784
    ]
  ]
};
const average = arr => arr.reduce( ( p, c ) => p + c, 0 ) / arr.length;
const pricesArr = myObj.prices.map(function(value,index) { return value[1]; })
const result = average( pricesArr );
console.log(result);

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