0
Hello, I have a news array(objects)
lista: Array<Noticia> = [];
From this array I need to find the author who has published the most news. A news has:
ID | Title | Tags | Author | Contents.
My initial idea was:
public totalPublicacoes(){
var autorM = '';
var autor = this.lista[0].autor;
var qtM = 0;
var qt = 0;
for(let i=0; i<this.lista.length; i++){
if(autor == this.lista[i].autor){
qt ++;
if(qt > qtM){
qtM = qt;
autorM = this.lista[i].autor;
}
}
}
console.log(autorM);}
With this my initial idea was to catch the author of the first object of the array
check if it was equal to the next author element of the array
if yes I was adding the Qt of times it appeared
if the current Qt was greater than the larger amount of apparitions
i updated the value of the highest appearance
and kept the name of the author who published the most.
But it’s not working, you can help me?
Our worked out! thank you very much! just a doubt, the type of these authors is obj right? so I will have to break-Ló to be able to compare the right values?
– Arthur Gabriel Silva Arantes
I’m actually trying to separate these values now so I can compare and say who published, but it’s hard since I don’t know what the name of the value says about the publication count..
– Arthur Gabriel Silva Arantes