출처: Type Challenges, https://github.com/type-challenges/type-challenges/blob/main/README.ko.md
3057 - Push
`Array.push`의 제네릭 버전을 구현하세요.
type Result = Push<[1, 2], '3'> // [1, 2, '3']
풀이
type Push<T, U> = T extends [...infer REST] ? [...REST, U] : never
infer를 사용해서 ...를 사용해서 배열 내부를 그대로 가져와서 연결하면 된다.
'알고리즘 > Type Challenges' 카테고리의 다른 글
3312 - Parameters (0) | 2023.09.17 |
---|---|
3060 - Unshift (0) | 2023.09.17 |
533 - Concat (0) | 2023.09.06 |
268 - If (0) | 2023.09.06 |
189 - Awaited (0) | 2023.09.06 |