---
title: Zig-zag matrix
id: 594810f028c0303b75339ad8
challengeType: 5
---
## Description
A ''zig-zag'' array is a square arrangement of the first
$N^2$ integers, where the
numbers increase sequentially as you zig-zag along the array's
anti-diagonals.
For example, given '''5''', produce this array:
Write a function that takes the size of the zig-zag matrix, and returns the
corresponding matrix as two-dimensional array.
## Instructions
## Tests
```yml
tests:
- text: ZigZagMatrix must be a function
testString: assert.equal(typeof ZigZagMatrix, 'function', 'ZigZagMatrix must be a function');
- text: ZigZagMatrix should return array
testString: assert.equal(typeof ZigZagMatrix(1), 'object', 'ZigZagMatrix should return array');
- text: ZigZagMatrix should return an array of nestes arrays
testString: assert.equal(typeof ZigZagMatrix(1)[0], 'object', 'ZigZagMatrix should return an array of nestes arrays');
- text: ZigZagMatrix(1) should return [[0]]
testString: assert.deepEqual(ZigZagMatrix(1), zm1, 'ZigZagMatrix(1) should return [[0]]');
- text: ZigZagMatrix(2) should return [[0, 1], [2, 3]]
testString: assert.deepEqual(ZigZagMatrix(2), zm2, 'ZigZagMatrix(2) should return [[0, 1], [2, 3]]');
- text: ZigZagMatrix(5) must return specified matrix
testString: assert.deepEqual(ZigZagMatrix(5), zm5, 'ZigZagMatrix(5) must return specified matrix');
```
## Challenge Seed
```js
function ZigZagMatrix(n) {
// Good luck!
return [[], []];
}
```