Startec

Startec

PODEM ME AJUDAR COM ESSA LÓGICA · Heuder

Mai 17, às 22:16

·

2 min de leitura

·

0 leituras

const _APOSTA_RESULTADO = [5, 16, 22, 23, 45, 60] const APOSTAS = [ [ { id: 1, nambers: "16,22,26,29,60", acertos:0 } ], [ { id: 2, nambers: "15,22,26,45,60", acertos:0 } ], [ { id: 3, n...
PODEM ME AJUDAR COM ESSA LÓGICA · Heuder

Esta estrutura tem um detalhe estranho: é um array no qual cada elemento é outro array, que por sua vez só tem um elemento (o objeto com id, números, etc). Não deveria ser um array de objetos?

Mas enfim, mantendo essa estrutura, a básica ideia é: cada elemento de APOSTAS é outro array, então para cada um eu faço um loop para verificar os acertos.

Aí uso split para separar os números, e verifico se cada um deles está no array de resultados. Algo assim:

for (const elemento of APOSTAS) {
 for (const aposta of elemento) { // cada elemento de APOSTAS é outro array, então faço outro for
 for (const n of aposta.nambers.split(',')) { // split para separar os números
 if (_APOSTA_RESULTADO.includes(parseInt(n))) { // parseInt para converter para número, e verifico se está no resultado
 aposta.acertos++;
 }
 }
 }
}
console.log(APOSTAS);

Outro detalhe, foi erro de digitação ou o nome da propriedade é nambers mesmo? Não deveria ser numbers? Enfim, fiz acima com nambers mesmo...


Claro, se é garantido que cada sub-array só tem uma única aposta, poderia trocar para:

for (const aposta of APOSTAS) {
 for (const n of aposta[0].nambers.split(',')) { // split para separar os números
 if (_APOSTA_RESULTADO.includes(parseInt(n))) { // parseInt para converter para número, e verifico se está no resultado
 aposta[0].acertos++;
 }
 }
}

No caso, aposta[0] pega o primeiro elemento do array. Como eu disse, se vc garante que sempre terá somente um, é o suficiente. Mas se puder ter vários, aí é melhor usar a primeira opção acima.


Continue lendo

DEV

How to Create an Evil Twin Access Point; Step-by-Step Guide
Step-by-Step Guide: Creating an Evil Twin An Evil Twin Access Point is a malicious wireless access point that is set up to mimic a legitimate one. It can be used to intercept sensitive information such as...

Jun 3, às 23:41

DEV

Atomic Design: A Methodology for Building Design Systems
Introduction Atomic Design is a methodology for creating design systems that recognizes the need to develop thoughtful design systems, rather than creating simple collections of web pages. In this approach,...

Jun 3, às 23:04

Hacker News

Thought Cloning: Learning to Think while Acting by Imitating Human Thinking
Language is often considered a key aspect of human thinking, providing us with exceptional abilities to generalize, explore, plan, replan, and adapt to new situations. However, Reinforcement...

Jun 3, às 23:00

AI | Techcrunch

YouTube rolls back its rules against election misinformation
YouTube was the slowest major platform to disallow misinformation during the 2020 U.S. election and almost three years later, the company will toss that policy out altogether. The company announced Friday...

Jun 3, às 22:57

DEV

Techinical Debt; what is it?
Imagine you're building a house. You want to finish it quickly, so you take some shortcuts along the way. You use low-quality materials, skip some important steps, and don't do thorough testing. The house is...

Jun 3, às 22:45

Marktechpost AI Research News

Researchers From UT Austin and UC Berkeley Introduce Ambient Diffusion: An AI Framework To Train/Finetune Diffusion Models Given Only Corrupted Data As Input
For learning high-dimensional distributions and resolving inverse problems, generative diffusion models are emerging as flexible and potent frameworks. Text conditional foundation models like Dalle-2, Latent...

Jun 3, às 22:40

DEV

Exploring Tech Paths: Discovering Exciting Possibilities
Table of Contents: Introduction Understanding the Diverse Fields in Tech The Search for the Right Tech Path A Case Scenario: Linda's Journey Actionable Advice for Exploring Tech Paths Success Story: Jane's...

Jun 3, às 20:55

Código Fonte

Ele usou o GPT-4 para criar uma nova linguagem de programação – Código Fonte
É inegável que os largos modelos de linguagem (LLMs), que são a base dos atuais algoritmos de Inteligência Artificial generativa, chegaram para revolucionar, nem que seja somente o ano de 2023, até a...

Jun 3, às 20:51

DEV

☸️ How to deploy a cost-efficient AWS/EKS Kubernetes cluster using Terraform in 2023
Introduction Variables Providers and locals The enclosing VPC network The actual Kubernetes cluster Docker registries S3 application bucket Outputs Conclusion Cover image generated locally by DiffusionBee...

Jun 3, às 20:18

AI | Techcrunch

Gig workers get paid, Fidelity slashes Reddit's valuation and AI conquers Minecraft
Hey, folks, welcome to Week in Review (WiR), TechCrunch’s regular newsletter that recaps the week in tech. Hope the summer’s treating y’all well — it’s a balmy 90 degrees here in NYC! — and that some...

Jun 3, às 20:15