Роман1479,
var matrix4D = [
[1, 1, 1, 1],
[1, 1, 1, 1],
[1, 1, 1, 1],
[1, 1, 1, 1]
];
var matrix4_D = [
[1, 1, 1, 3],
[1, 1, 6, 1],
[1, 2, 1, 10],
[9, 1, 1, 1],
[1, 1, 11, 1]
];
var matrix5D = [
[1, 2, 3, 4, 5],
[1, 1, 1, 3, 4],
[1, 1, 1, 1, 1]
];
function function_matrix(arr){
var num = arr[0].length;
var l = Math.min(num, arr.length)
var n = --num;
var res = [];
for (var i = 0; i < l; i++) {
res.push(arr[i][n])
--n
}
return res
}
alert(function_matrix(matrix4D));
alert(function_matrix(matrix4_D));
alert(function_matrix(matrix5D));