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

130
Views
how to increase the value of an object dependent on the key name

I want to increase the value depending on the key name. I have an array with scores:

[50,50,60,70,80,90,90,100]
Grade A: score<100 and score>=90
Grade B: score<90 and score>=80
Grade C: score<80 and score>=60
Grade D: score<60 and score>=0

In the end, I want to get an object with countable scores:

{A:0, B:0, C:0, D:0 };
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You could take a Proxy and change dependent properties.

const
    table = { S: 0, A: 0, B: 0, C: 0, D: 0, X: 0 },
    change = new Proxy(table, {
        set: function(obj, prop) {
            if (prop === 'B') obj.S++;
            obj[prop]++;
            return true;
        },
    });

change.B++;

console.log(table);

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!