Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

132
Views
Calcular cuántas veces aparece un objeto en una matriz en otra matriz profundamente anidada con Reactjs

Estoy tratando de comparar cuántas veces los objetos de una matriz ocurren dentro de objetos profundamente anidados en otra matriz y renderizar una tarjeta.

Aquí está mi objeto de datos:

 collections: [{ amount: 3 gameType: "rts" gameWin: true entryId: 1 }, { amount: 5 gameType: "shooter" gameWin: true entryId: 2 }, { amount: 11 gameType: "rpg" gameWin: true entryId: 3 }, { amount: 12 gameType: "blackjack" gameWin: true entryId: 4 }] currencyCode: "USD" entryId: "596" playerId: "1112331asdasx" receipt: "1112331asdasx711a6b1" selections: [{ expiryTime: 1654534799000 maxPlays: 10 spins:[{ prizes: [] receipt: "0f36f427d43aac5d63f6074c50e04800507d6863" results:[{ gameType: "rts" entrySelnSpinId: 3505 }, { gameType: "rpg" entrySelnSpinId: 1505 }, { gameType: "rpg" entrySelnSpinId: 2505 }] }, { prizes: [] receipt: "427d43aa4800507d6863c5d63f6074c50e00f36f" results:[{ gameType: "shooter" entrySelnSpinId: 3205 }, { gameType: "shooter" entrySelnSpinId: 1305 }, { gameType: "blackjack" entrySelnSpinId: 2105 }] }] }] status: "active"

Mi intento de resolver este problema:

 const calculatedAmount = selections.map((selection:any)=>{ return selection.spins.forEach((spin:any)=>{ spin.results.map((result:any)=>{ console.log(result) return collections.filter(collection => collection.gameType === result.gameType).length; }) }) })

Aquí estoy tratando de representar un elemento que muestra el recuento de cuántas veces ocurre el tipo de juego de las colecciones en la matriz de resultados dentro de las selecciones .

 {collections.map((collection: IReelMoneyCollection) => { return <GamesCard totalodds={ calculatedAmount + " / " + collection.targetAmount} />; })}

¿Cómo puedo calcular cuántas veces diferentes se producen gameType de la matriz de colecciones dentro de los resultados en la matriz de selecciones y renderizar mi componente con él?

Como renderizar una tarjeta de juego para RTS que muestra 2, ya que solo aparece dos veces. Luego, otra carta para Shooter que muestra 2, una para Blackjack que muestra 1.

about 4 years ago · Santiago Gelvez
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!