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

142
Visualizações
react js build list of objects from another list of objects

i want to build new list of objects with average value from another list of objects The original list :

original_list = [{"time":16485,"max_count":6,"min_count":4,"max_ca":10,"min_ca":8},{"time":16495,"max_count":12,"min_count":10,"max_ca":8,"min_ca":6},]

The new list i want to get

new_list = [{"time":16485,"average_count":5,"average_ca":9},{"time":16495,"average_count":11,"average_ca":7,]

I tried this code but it doesn't work

const new_list = [];
original_list.map((element) => { 'time': element.time, 'average_count': 
$(element.max_count)/2 + $(element.min_count)/2, 'average_ca': (element.max_ca)/2 + $(element.min_ca)/2 });

but i got lot of syntax error, any idea how i can get the result please

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

0

You need to wrap the function body in parentheses. It should look like this:

const new_list = original_list.map((element) => ({ 'time': element.time, 'average_count': $(element.max_count)/2 + $(element.min_count)/2, 'average_ca': (element.max_ca)/2 + $(element.min_ca)/2 }));

Here are the docs on arrow functions

about 4 years ago · Juan Pablo Isaza Relatório

0

I'd do something like this:

const new_list = original_list.map((element) => ({
  time: element.time,
  average_count: (element.max_count + element.min_count) / 2,
  average_ca: (element.max_ca + element.min_ca) / 2,
}));
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