function createEqualLengthArray(array1, array2) { while(array1.length < array2.length) { console.log(array1.length, array2.length) let randIdx = Math.floor(Math.random() * array2.length); let randElement = array2.splice(randIdx, 1)[0]; array1.push(randElement) } return {hand1: array1, hand2: array2} } const pokemonCard = [ { id: 4, name: "Charmander", type: "fire", base_experience: 62 }, { id: 7, name: "Squirtle", type: "water", base_experience: 63 }, { id: 11, name: "Metapod", type: "bug", base_experience: 72 }, { id: 12, name: "Butterfree", type: "flying", base_experience: 178 }, { id: 25, name: "Pikachu", type: "electric", base_experience: 112 }, { id: 39, name: "Jigglypuff", type: "normal", base_experience: 95 }, { id: 94, name: "Gengar", type: "poison", base_experience: 225 }, { id: 133, name: "Eevee", type: "normal", base_experience: 65 }, ], let hand1 = []; let hand2 = [...this.props.pokemonCards] const hands = createEqualLengthArray(hand1, hand2)
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter