Роман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, num){
var l = Math.min(num, arr.length/num)
var n = --num;
var res = [];
for (var i = 0; i < l; i++) {
res.push(arr[n])
n += num
}
return res
}
alert(function_matrix(matrix4D, 4));
alert(function_matrix(matrix4_D, 4));
alert(function_matrix(matrix5D, 5));