Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

108
Vistas
Get all possible combinations from two array

Imagine we have two arrays like below

let result = []
let array1 = ['2h', '3h', '4h', '5d', '8d']
let array2 = ['Kd', 'Ks']

I need to take each element from array2 and replace each element into array one by one and store in result

Result should be like this

result = ['Kd', '3h', '4h', '5d', '8d']
         ['2h', 'Kd', '4h', '5d', '8d']
         ['2h', '3h', 'Kd', '5d', '8d']
         .....
         ['Ks', '3h', '4h', '5d', '8d']
         ['2h', 'Ks', '4h', '5d', '8d']
         ['2h', '3h', 'Ks', '5d', '8d']
         .....

And also replace whole array2 in array1

result = ['Kd', 'Ks', '4h', '5d', '8d']
         ['2h', 'Kd', 'Ks', '5d', '8d']
         .....
         ['Kd', 'Ks', '4h', '5d', '8d']
         ['Kd', '3h', 'Ks', '5d', '8d']
         ['Kd', '3h', '4h', 'Ks', '8d']
         .....

This my current code, need to analyze poker hand for each player and then sort by strength

let ranks = ['2','3','4','5','6','7','8','9','T','J','Q','K','A']
let suits = ['h','d','c','s']
let gameTypes = ['texas-holdem','omaha-holdem','five-card-draw']
//Lets learn poker rules
// Card == table + player
let royalFlush
let straightFlush
let fourKind
let fullHouse
let royal
let straight
let threeKind
let twoPair
let twoKind
let highCard
var combos = []

function variants(table, player) {
    let result = []
    let tableArr = table.split(/(?=(?:..)*$)/)
    let playerArr = player.split(/(?=(?:..)*$)/)
    playerArr.forEach((item) => {
        for(let i = 0; i < tableArr.length; i++) {                                              
            const tempArray = [...tableArr];                                                           
            tempArray[i] = item;                                                                     
            result.push(tempArray);                                                                  
        }                                                                                          
    });                                                                                          
    return result 
}
function sortHand(input) {
    let handAnal = input.split(' ')
    handAnal.forEach((e, index) => {
        if(index == 0 || index == 1) {
            return
        } else {
            combos.push(variants(handAnal[1], handAnal[index]))
        }
    })
}

//console.log(sortHand('texas-holdem 4cKs4h8s7s Ad4s Ac4d As9s KhKd 5d6d'))
sortHand('texas-holdem 2h3h4h5d8d 9hJh')
console.log(combos);
//console.log(sortHand('omaha-holdem 3d3s4d6hJc Js2dKd8c KsAsTcTs Jh2h3c9c Qc8dAd6c 7dQsAc5d'))
//console.log(sortHand('five-card-draw 7h4s4h8c9h Tc5h6dAc5c Kd9sAs3cQs Ah9d6s2cKh 4c8h2h6c9c'))
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Here's my solution for it.

let result = [];                                                                             
let array1 = ["2h", "3h", "4h", "5d", "8d"];                                                 
let array2 = ["Kd", "Ks"];                                                                   
                                                                                               
array2.forEach((item) => {                                                                                for(let i = 0; i < array1.length; i++) {                                              
  const tempArray = [...array1];                                                           
  tempArray[i] = item;                                                                     
  result.push(tempArray);                                                                  
  }                                                                                          
});                                                                                          
                                                                                      
console.log(result); 

Here, we're iterating over the array2 and taking each item. And for every item of the array2 we're iterating over the first array and making a copy of it and storing it in the tempArray. After that we put the current item of the first array and put it the tempArray at the index i from the for loop.

about 4 years ago · Juan Pablo Isaza Denunciar

0

Sorted manually, without any math or clever solution :(

function variants(table, player) {
    let result = []
    let tableArr = table.split(/(?=(?:..)*$)/)
    let playerArr = player.split(/(?=(?:..)*$)/)
    playerArr.forEach((item) => {
        for(let i = 0; i < tableArr.length; i++) {                                              
            const tempArray = [...tableArr];                                                           
            tempArray[i] = item;                                                                     
            result.push(tempArray);                                                                  
        }                                                                                     
    });    
    for(let i = 1; i <= 10; i++) {
        const tempArray = [...tableArr];                                                             
        if(i<=4) {
            tempArray.splice(0, 1, playerArr[0])
            tempArray.splice(0+i, 1, playerArr[1])
        } else if(i<=7) {
            tempArray.splice(1, 1, playerArr[0])
            tempArray.splice(-3+i, 1, playerArr[1])
        } else if(i<=9) {
            tempArray.splice(2, 1, playerArr[0])
            tempArray.splice(-5+i, 1, playerArr[1])
        } else {
            tempArray.splice(3, 1, playerArr[0])
            tempArray.splice(4, 1, playerArr[1])
        }
        result.push(tempArray);
    }                                                                                          
    return result 
}
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda