You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

58 lines
1.6 KiB

let eventos = []//array de 1000 objetos
let categorias = [["formatura","casamento"],["aniversário","shows"],["gospel","infantil"]]
let keywords = ["futebol", "dança","praia","skate", "tênis","almoço","janta","lanche","sobremesa","bolo"]
for (let i = 0; i <= 1000; i++) {
const evento = {}
const categoria = Math.trunc(Math.random() * (2) + 0)
const titulo = Math.trunc(Math.random() * (10))
if (i % 6 == 0) {
//insere na categoria formatura ou casamento
evento.categoria = categorias[0][categoria]
} else if (i % 5 == 0){
//insere na categoria aniversario ou shows
evento.categoria = categorias[1][categoria]
} else {
//insere na categoria gospel ou infantil
evento.categoria = categorias[2][categoria]
}
evento.titulo = `evento-${i} ${keywords[titulo]}`
eventos.push(evento)//adiciona o objeto evento no array eventos
}
const contadores = {}
for (const subcategoria of categorias) {
for (const categoria of subcategoria) {
contadores[categoria] = 0
}
}
const contadorKeywords = {}
for (const keyword of keywords) {
contadorKeywords[keyword] = 0
}
for (const evento of eventos) {
contadores[evento.categoria] += 1
for (const keyword of keywords){
if (evento.titulo.indexOf(keyword) > -1){
contadorKeywords[keyword] = contadorKeywords[keyword] + 1
}
}
}
console.log("Array de eventos: ", eventos.slice(0,11))
console.log("Objeto de categorias preenchido:", contadores)//contagem de eventos por categoria
console.log("Objeto de keywords preenchido", contadorKeywords)//contagem de eventos por keywords