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

241
Views
Functional Programming, JavaScript, chaining, and no external library to calculate average on array of objects

I want to use Functional Programming, JavaScript, chaining, and no external library to reduce an array of objects to the average of the grade of the element with the condition that enrolled >1. So far I'm able to calculate the sum under the requested condition But how can I calculate the average? ( Note that I want to use Functional Programming, JavaScript, chaining, and no external library)

Here is what I have come so far ...

let enrollment= [
    {enrolled: 2, grade:100},
    {enrolled: 2, grade:80},
    {enrolled: 1, grade:89}
]

const sum = (accumulator, curr) => accumulator + curr.grade;


enrollment
    .filter( elem => elem.enrolled >1)
    .reduce(sum,0)

Now how do I chain an average function to the above block of code? Thanks in advance

about 4 years ago · Juan Pablo Isaza
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!