function 분류기(...rest : (string|number)[]) : [string[], number[]]{
let a : string[]
let b : number[]
rest.forEach((e)=>{
if(typeof e === 'string'){
a.push(e)
} else{
b.push(e)
}
})
return [a, b]
}
선생님의 코드는 이해했으나, 제가 처음에 작성한 코드는 이렇습니다.
TypeError: Cannot read property 'push' of undefined
라는 에러를 받는데 a.push(e)의 a에 커서를 올리면 a의 타입이 string[]라고 나옵니다.
즉, 왜 해당 에러가 발생했는지 몰겠습니다.