function flatten(args) {
let result = [];
const flattens = function(stack, result) {
for(let j = 1; j < stack.length; j += 1) {
if (Array.isArray(stack[j])) {
flattens(stack[j], result);
} else {
result.push(stack[j])
}
}
}
for(let i = 0; i < args.length; i += 1) {
flattens(args[i], result)
}
return result
}
数组扁平化
function flatten(args) {
let result = [];
const flattens = function(stack, result) {
for(let j = 1; j < stack.length; j += 1) {
if (Array.isArray(stack[j])) {
flattens(stack[j], result);
continue
}
result.push(stack[j])
}
}
for(let i = 0; i < args.length; i += 1) {
if ( Array.isArray(args[i])) {
flats(args[i])
} else {
result.push(args[i])
}
}
return result
}