题解 | #数组扁平化#
数组扁平化
https://www.nowcoder.com/practice/5d7e0cf4634344c98e6ae4eaa2336bed
const _flatten = (arr) => { // 判断arr是否为数组 if (!Array.isArray(arr)) return; let result = []; const inner = (array) => { array.forEach((item) => { if (Array.isArray(item)) { // 如果当前项还是数组就继续遍历每一项 inner(item); } else { result.push(item); } }); }; inner(arr); return result; };