Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

155
Visualizações
Pasar el valor de mi cuadro de texto a mi código de secuencia de comandos para convertirlo en una función dinámica

Estoy haciendo un sistema de emparejamiento. Mi función actual emparejó a los jugadores con una diferencia de peso de 20. Como puede ver en el resultado de mi fragmento, 1900 vs 1920 se han emparejado porque declaré un different = 20, . Ahora mi objetivo es hacer una dinámica diferente. Quiero pasar el valor de mi cuadro de texto a mi different . Quiero hacer coincidir el jugador 2 y el jugador 3 . Tienen 30 de diferencia de peso .

Si escribo 30 en mi cuadro de texto. El jugador 2 y el jugador 3 deben coincidir

. ¿Cómo puedo conseguir esto? Cualquier ayuda será apreciada. Gracias.

 var difff = document.getElementById('diff'); // I have tried also to set a variable here to get the textbox value and pass it to my "different = difff" but it is not working. const source = [ { entryID: 1, entryName: "player1", weight: 1900, }, { entryID: 2, entryName: "player2", weight: 1920, }, { entryID: 3, entryName: "player3", weight: 1950, }, ]; function combine( data = [], different = 20, // I have tried to change the "20" to my id "difff" So i can pass my textbox's value but it is not working. maxGroupSize = 2, sortedStatement = (a, b) => a.weight - b.weight ) { const sortedData = [...data].sort(sortedStatement); // "weight" must be in ascending order const dataGroups = sortedData.reduce((acc, item) => { const findedAccItem = acc.find( (accItem) => accItem.length < maxGroupSize && // if the array is not filled accItem[0].weight + different >= item.weight && // and if the minimum is in the acceptable range !accItem.find((obj) => obj.entryName === item.entryName /* || obj.entryID === item.entryID */) // and if there are no matches ); if (findedAccItem) { findedAccItem.push(item); } else { acc.push([item]); } return acc; }, []); const namedDataGroups = dataGroups.reduce((acc, item, index) => { // added an index as a prefix because the keys can match const key = [index, ...item.map((item) => item.weight)].join("_"); acc[key] = item; return acc; }, {}); return namedDataGroups; } // default example console.log("Example #1: ", combine(source));
 <input id="diff" type="number" value="20"/> // I need to pass this on my script.

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda