Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

140
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!