1
I am learning in Rra Javascript, but I came across a situation that I could not solve. I’m looking to create a chart where The horizontal line will be the date (I’ve already managed to eliminate the repeating dates) and the vertical line the number of times it repeats, so I’d like to know how to count the dates that repeat in sequence and play within an array/vector. I’m using Firebase as my database.
Code: Function table() { ref = Fire_input()
var coluna = []
ref.child("Tabela").on("child_added", function (snapshot) {
dadosT = snapshot.key
ref.child("Tabela").child(dadosT).on("value", function (snapshot) {
dados = snapshot.val(); // Array completo
//CRIA O GRÁFICO
coluna.push(dados.Data) // Array com todas as datas
// ELIMINA AS DATAS REPETIDAS
var novaColuna = coluna.filter(function (este, i) {
return coluna.indexOf(este) === i;
});
// SOMA AS DATAS REPETIDAS
??????
});
});
}
Your question is not clear. For example: do you want the count of repeated values in sequence, or the totality of repetitions? How will you know what word the returned array is referring to? Wouldn’t it be better to return an object (hashtable/dictionary)? Elaborate better.
– Seu Madruga
Repeaters will always be in sequence?
– LeAndrade
Object.defineProperties(Array.prototype, { Count: { value: Function(value) { Return this.filter(x => x==value).length; } } }); arr.Count("John") expected result: 4
– Juliano Henrique
for me no matter if it will bring in sequence only count the equal values that repeat, but if bring in better sequence even, thank you.
– Jeffson Oliveira
@Jeffsonoliveira, have you at least tried to solve this problem? Please click [Edit] to add the code you tried to do...
– Luiz Felipe
If the array is
["João", "Maria", "José", "João"]
what must be the return?[2, 1, 1]
? Or does John only count twice if he has more than one occurrence in a row? I think that’s what they meant when they asked if the repeaters are in sequence.– hkotsubo
Blz will edit my question by entering my code.
– Jeffson Oliveira