SHARE
TWEET

Untitled

a guest Nov 15th, 2017 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const Board = (fillWith = null) => ({
  2.     winner: null,
  3.     squares: new Array(9).fill(fillWith),
  4.     winningSquares: []
  5. });
  6.  
  7. const game = new Board( new Board() );
  8.  
  9. const take = (iA, iB, token) => {
  10.   game.squares[iA].squares[iB] = token;
  11. }
  12.  
  13. take(0,0,'x');
  14. take(8,1,'o');
  15.  
  16. game.squares.map( (miniboard, i) => console.log({[i]: miniboard.squares}))
  17.    
  18. { 0: [ 'x', null, null, null, null, null, null, null, null ] }
  19. { 1: [ null, null, null, null, null, null, null, null, null ] }
  20. { 2: [ null, null, null, null, null, null, null, null, null ] }
  21. { 3: [ null, null, null, null, null, null, null, null, null ] }
  22. { 4: [ null, null, null, null, null, null, null, null, null ] }
  23. { 5: [ null, null, null, null, null, null, null, null, null ] }
  24. { 6: [ null, null, null, null, null, null, null, null, null ] }
  25. { 7: [ null, null, null, null, null, null, null, null, null ] }
  26. { 8: [ null, 'o', null, null, null, null, null, null, null ] }
  27.    
  28. { 0: [ 'x', 'o', null, null, null, null, null, null, null ] }
  29. { 1: [ 'x', 'o', null, null, null, null, null, null, null ] }
  30. { 2: [ 'x', 'o', null, null, null, null, null, null, null ] }
  31. { 3: [ 'x', 'o', null, null, null, null, null, null, null ] }
  32. { 4: [ 'x', 'o', null, null, null, null, null, null, null ] }
  33. { 5: [ 'x', 'o', null, null, null, null, null, null, null ] }
  34. { 6: [ 'x', 'o', null, null, null, null, null, null, null ] }
  35. { 7: [ 'x', 'o', null, null, null, null, null, null, null ] }
  36. { 8: [ 'x', 'o', null, null, null, null, null, null, null ] }
RAW Paste Data
Top