Click to reopen instructions.

This assessment consists of functions you need to write involving manipulating arrays and objects. And maybe arrays of objects. It is a closed book assessment. You should stay on this tab until you are done and there should be no talking. This assessment is about how much you understand. There are no automatic tests but you can use the REPL to test things yourself.

Note: on this assessment you will be asked to write functions that call other functions you will write as part of the assessment. If you don’t know how to write one function you can still get full credit for a function that is supposed to call it as long as your code calls it appropriately, i.e. with correct syntax and passing the right arguments.

You can move through the questions with the arrows at the upper right next to the 1 of indicator so if you're not sure how to write one function move on to another one and come back if you have time at the end. I want to see how much you do know. Note: you can also click on thingsLikeThis in these instructions and the questions to copy them to the clipboard to avoid spelling mistakes. (I.e. click to copy and then ⌘-v to paste wherever you want.)

When you are done, please click on your Github username above and submit a GitHub pull request of the branch and request me as a reviewer. Doing this correctly is part of the assessment. If you are unsure how to request a review, please ask for help!

Put definitions here.

Revisions:

Questions of

Write a function named makeRow that takes no arguments and returns a new three-element array where each element is the empty string, ''.

Write a function named makeBoard that takes no arguments and returns a 3x3 array. That is, it should return an array containing three elements, each of which is a new array containing three elements. The elements of the inner arrays should all be the empty string, ''. In other words, the inner arrays are rows such as are returned by the makeRow function you just wrote, which you are free to use here if you want.

Write a function named makeMove that takes three arguments: a string, specifying a mark (either 'X' or 'O'); a number specifying a row; and a number specifying a column. It should return an object with three properties, mark, row, and column, each with the value of the corresponding argument.

Write a function named placeMark that takes a 3x3 array like the ones returned by makeBoard and an object like the ones returned by makeMove and sets the element of the array at the row and column specified in the move object to the move's mark.

The function does not need to return any specific value but after calling it the array passed as the first argument should be modified. For instance, after:

  let board = makeBoard();
      let move = makeMove('X', 1, 1);
      placeMark(board, move);

the expression board[1][1] should evaluate to 'X'.

Write a function named allTheSame that takes an array of three elements and returns true if all three elements are === to each other and false otherwise. For instance, allTheSame(['X', 'X', 'X']) should return true.

Write a function named extractColumn that takes a 3x3 array like the ones returned by makeBoard and an index from 0 to 2, inclusive, and returns a three-element array containing the values in the column specified by the index, assuming the inner arrays represent rows. For instance if board is the array:

   [
      ['X', '', ''],
      ['O', '', ''],
      ['', 'X', '']
      ]

then extractColumn(board, 0) should return ['X', 'O', '']

Write a function named recordMove that takes two arguments: an array and a move object, like the ones returned by makeMove. It should add the given move to the end of the array.

The function does not need to return any specific value but after it is called the array argument should be one longer than it was before the call and the last element of the array should be the object passed as the second argument.

Write a function named rowForMove that takes two arguments: an array of move objects like the ones collected in recordMove and a number which is an index into that array. It should return the row value (a number) of the move at the given index.

For example after these two lines are executed:

   let moves = [];
      recordMove(moves, makeMove('X', 1, 2));

the call rowForMove(moves, 0) should return 1.

Write a function named placeMoves that takes two arguments: a 3x3 array like the ones returned by makeBoard and an array of moves such as might be built up by repeatedly calling recordMove. The function should call placeMark to place the mark for each move in the array of moves in the correct position on the board array.

The function does not need to return any specific value though obviously all the calls to placeMark will have updated the board array argument. For instance after these lines are executed:

   let moves = [];
      let board = makeBoard();
      recordMove(moves, makeMove('X', 1, 1));
      recordMove(moves, makeMove('O', 0, 0));
      recordMove(moves, makeMove('X', 0, 1));
      placeMoves(board, moves);
  

then the board should be in this state: [['O', 'X', ''], ['', 'X', ''], ['', '', '']]

REPL