Diagonally iterate in reverse each item in a rectangular 2D array

by BenR   Last Updated November 08, 2018 21:13 PM

How would a loop be constructed to iterate all items of a 2D array in reverse, and diagonally? For example, iterating in that way with the following 2D array, would output the result below:

2D Array

[
  ['a', 'b', 'c'],
  ['d', 'e', 'f'],
  ['g', 'h', 'i'],
  ['j', 'k', 'l']
]

Output

l
k, i
j, h, f
g, e, c
d, b
a

The 2D array can be rectangular, not limited to square (2x2, 3x2, 2x3, etc.). How would I go about implementing a loop like that?



Related Questions




Everything is a Scene Node?

Updated July 18, 2016 08:05 AM

How to use nodes in scene graph for game logic

Updated August 19, 2018 14:13 PM