Hello, I have an array of news (objects)
lista: Array<Noticia> = [];
From this array I need to find out the author who most published the news. One news item has:
ID | Title | Tags Author | Content .
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);}
So my initial idea was to get the author of the first array object
check if it was the same as the next author element of the array
If yes I added the qt of times it appeared
if the current qt was greater than the greater number of appearances
I updated the highest appearance value
and kept the name of the author who in most thesis published.
But it's not working, can you help me?