Solution Review: Creating Boards

Overview of the solution to the exercise "creating boards."

We'll cover the following

Solution

First, create a two-dimensional array. Since the sizes may vary, we cannot hardcode an array. So, settle for loops or methods which update the array dynamically. Create an array of size length (first argument). With this array, assign each index to an array of size width (second argument) to create a two-dimensional array. This is the board. Once we have the array, the only thing that remains is populating it with values. Iterate the array pieces (third argument) and see for each for the following.

  • row property is less than the length argument (first argument) value and greater than or equal to 0.
  • col property is less than the width argument (second argument) value and greater than or equal to 0.

If both conditions are satisfied, populate the array at the corresponding index with the value of the property value. All remaining values are assigned to " " value.

Get hands-on with 1200+ tech skills courses.