SHARE
TWEET

Untitled

a guest Oct 14th, 2019 83 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import cards from './GameResources'
  2.  
  3. const generateBoard = () => {
  4.   let board = []
  5.  
  6.   for (let i = 0; i < cards.length * 2; i++) {
  7.     let randomCard
  8.  
  9.     do {
  10.       randomCard = cards[Math.floor(Math.random() * cards.length)]
  11.     } while (
  12.       board.filter(element => element.type === randomCard.type).length >= 2
  13.     )
  14.  
  15.     board.push(Object.assign({}, randomCard))
  16.   }
  17.  
  18.   return board
  19. }
  20.  
  21. export default generateBoard
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top