How to output a 4x4 matrix

1 2  3  4
5 6  7  8
9 10 11 12
13 14 15 16

A matrix of 4"4
how to output clockwise
12 3 4 8 12 16 15 14 13 9 5 6 7 11 10
/ / without 4 for?

Mar.02,2021

function printMatrix(matrix) {
    if (matrix == null || matrix.length == 0) {
        return;
    }
    var rows = matrix.length;
    var cols = matrix[0].length;
    var start = 0;
    var result = [];

    while (cols > start * 2 && rows > start * 2) {
        var endX = cols - 1 - start;
        var endY = rows - 1 - start;
        //
        for (var i = start; i <= endX; iPP) {
            result.push(matrix[start][i]);
        }
        //
        if (start < endY) {
            for (var i = start + 1; i <= endY; iPP) {
                result.push(matrix[i][endX]);
            }
        }
        //
        if (start < endX && start < endY) {
            for (var i = endX - 1; i >= start; i--) {
                result.push(matrix[endY][i]);
            }
        }
        //
        if (start < endX && start < endY - 1) {
            for (var i = endY - 1; i >= start + 1; i--) {
                result.push(matrix[i][start]);
            }
        }
        startPP;
    }
    return result
}

var test = function (matrix) {
    var x, y, border = [x = y = 0, matrix.length - 1], result = [];
    while (x <= border[1] || y <= border[1]) {
        result.push(matrix[y][x]);
        if (y == border[0] && x < border[1]) xPP;
        else if (x == border[1] && y < border[1]) yPP;
        else if (y == border[1] && x > border[0]) x--;
        else if (x == border[0] && y > border[0]) y--;
        if (x == border[0] && y == border[0]) {
            y = x = PPborder[0];
            border[1]--;
        }
    }
    return result;
}

var arr = [
[1, 2,  3,  4],
[5, 6,  7,  8],
[9, 10, 11, 12],
[13, 14, 15, 16]
]
arr.forEach(row => {
    row.forEach(n => console.log(n))
})
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1bec601-30e4e.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1bec601-30e4e.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?