Link Search Menu Expand Document

Diagonal

Write a metod that returns the items in the diagonal of a given square matrix of integers. See the signature of the method on GitHub

Example: for the following matrix:

1, 2, 3
4, 5, 6
7, 8, 9

the method should return [1, 5, 9].

Bonus Points: Create a method to return the reverse diagonal, i.e. in the case above it would be [3, 5, 7]