Challenge 2: Equivalent Objects

Check for the equivalent elements in the array and print out the findings as a table.

Problem statement

Change your code so that it outputs the following table containing an equal number of rows and columns. The objects in the given array should be represented as labels of the first row and the first column of the table.

Fill each cell with the result that == returns for the row and column header objects against that cell.

Tip: Break into subtasks

  1. Write some code that collects an array of arrays or an array containing all rows. This is a rows array with many arrays, each of which holds six results (cells) for each comparison.

  2. Add the row label (the object’s representation) to the beginning of the row. Which operator will you use?

  3. Make sure each cell is five characters wide (wide enough to hold all data and header labels).

  4. Join the cells in each row with the " | " string.

  5. Add the table headers row.

Final output

Your table should look like this:

Try it yourself

objects = [true, false, nil, 0, 1, "", []]
# Start your code here