function flatten(arg){ const d=[]; if(!Array.isArray(arg)){ d.push(arg); }else{ flatten(arg.reduce((a,b)=>a.concat(b))); } return d; } console.log(flatten