maternik,
var mas2 = [
[1],
[2],
[3, 5, 7],
[4],
[],
[6],
[],
[8],
[]
];
var param = [1, 1, 1, 1, 1, 1, 1, 1, 1];
var out = [];
var N = param.length;
for (var i = 0; i < N; i++) out[i] = recurs(i);
alert(out);
function recurs(i) {
var f = param[i];
if (mas2[i].length) {
var Nc = mas2[i].length;
for (var j = 0; j < Nc; j++) f += recurs(mas2[i][j])
}
return f
}