题解 | #数组扁平化#
数组扁平化
http://www.nowcoder.com/practice/5d7e0cf4634344c98e6ae4eaa2336bed
const _flatten = arr => {
// 补全代码
var res=[]
//循环遍历数组,当遍历的不是数字时重新赋值数组和开始的下标
for(var i=0;i<arr.length;i++){
if((typeof arr[i])!='number'){
arr=arr[i];
i=-1;
}else{
res.push(arr[i])
}
}
return res
}