Daily-Interview-Question icon indicating copy to clipboard operation
Daily-Interview-Question copied to clipboard

myflatten

Open s-jd opened this issue 3 years ago • 0 comments

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
}

s-jd avatar Mar 29 '22 08:03 s-jd