forked from phaserjs/phaser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCheckMatrix.js
More file actions
46 lines (41 loc) · 940 Bytes
/
Copy pathCheckMatrix.js
File metadata and controls
46 lines (41 loc) · 940 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/**
* A Matrix is simply an array of arrays, where each sub-array (the rows) have the same length:
*
* let matrix2 = [
* [ 1, 1, 1, 1, 1, 1 ],
* [ 2, 0, 0, 0, 0, 4 ],
* [ 2, 0, 1, 2, 0, 4 ],
* [ 2, 0, 3, 4, 0, 4 ],
* [ 2, 0, 0, 0, 0, 4 ],
* [ 3, 3, 3, 3, 3, 3 ]
*];
*/
/**
* [description]
*
* @function Phaser.Utils.Array.Matrix.CheckMatrix
* @since 3.0.0
*
* @param {array} matrix - [description]
*
* @return {boolean} [description]
*/
var CheckMatrix = function (matrix)
{
if (!Array.isArray(matrix) || matrix.length < 2 || !Array.isArray(matrix[0]))
{
return false;
}
// How long is the first row?
var size = matrix[0].length;
// Validate the rest of the rows are the same length
for (var i = 1; i < matrix.length; i++)
{
if (matrix[i].length !== size)
{
return false;
}
}
return true;
};
module.exports = CheckMatrix;