function flatten(a, r) {
if (!r) {
r = [];
}
for (var i = 0; i < a.length; i++) {
if (a[i].constructor == Array) {
flatten(a[i], r);
} else {
r.push(a[i]);
}
}
return r;
}
flatten([[1, 2],[3, 4, 5], [6, 7, 8, 9,[11,12,[12,13,[14]]]],10]);
// =>[1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 12, 13, 14, 10]
参考:开开心心机试题