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

133
Views
I have an array full of objects. All objects have key author and publisher. I want to take out the publisher who publish most different authors

Here I am setting the empty object with key (publisher) and value author;

Also I tried and I push them in the empty array

let publisherAutors = {};
let pushedAutorsPerPublisher = [];

With this for loop i`m taking the elements from my library , which are books(objects), and i take out the publishers and the autors

for (let i = 0; i < library.length; i++) {
  const element = library[i];
  autorCount = 0;

I think my problem is here , with the if statements, i wanna compare but something is going wrong

  if (
    element.publisher === element.publisher &&
    element.autor === element.autor
  ) {
    console.log(`Yes`);

Here i push to the empty array

    pushedAutorsPerPublisher.push(element.publisher, element.autor);
    console.log(element.publisher, element.autor);
  }

Here I`m adding key/ value to the empty object, but Its not helping me , because they goes only once in the empty object

  publisherAutors[element.publisher] = element.autor;
}

console.log(publisherAutors);
console.log(pushedAutorsPerPublisher);

My main problem is to make object , or array that holds them and count how many different authors have each publisher .

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

My suggestion would be to store every publisher's published authors into their respective arrays, and then use filter and indexOf to filter out the duplicates. Then, return the largest array.

Here is a link to how you would use filter and indexOf to filter duplicates.

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!