Advanced-Frontend / Daily-Interview-Question

我是依扬(木易杨),公众号「高级前端进阶」作者,每天搞定一道前端大厂面试题,祝大家天天进步,一年后会看到不一样的自己。
https://muyiy.cn/question/
27.43k stars 3.29k forks source link

myflatten #567

Open s-jd opened 2 years ago

s-jd commented 2 years ago
function myflatten(arr){
  let res = []
  let temp
  while(arr.length > 0){
    temp = arr.shift()
    console.log("temp",temp);
    if(temp instanceof Array){
      arr.unshift(...temp)
    }
    else{
      res.push(temp)   
    }
  }
  return res
}