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

132
Visualizações
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 Respostas
Responde à pergunta

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 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