본문 바로가기

728x90

FE/type-challenge

(31)
26401. JSONSchema2TS 문제 Implement the generic type JSONSchema2TS which will return the TypeScript type corresponding to the given JSON schema. cases // + Primitive types type Type1 = JSONSchema2TS type Expected1 = string type Result1 = Expect type Type2 = JSONSchema2TS type Expected2 = number type Result2 = Expect type Type3 = JSONSchema2TS type Expected3 = boolean type Result3 = Expect // - Primitive types // + Enu..
25270. Transpose 문제 The transpose of a matrix is an operator which flips a matrix over its diagonal; that is, it switches the row and column indices of the matrix A by producing another matrix, often denoted by AT. type Matrix = Transpose ; // expected to be [[1]] type Matrix1 = Transpose ; // expected to be [[1, 3], [2, 4]] type Matrix2 = Transpose ; // expected to be [[1, 4], [2, 5], [3, 6]] cases type cases =..
25170. ReplaceFirst 문제 Implement the type ReplaceFirst which will replace the first occurrence of S in a tuple T with R. If no such S exists in T, the result should be T. cases type cases = [ Expect, Expect, Expect, Expect, Expect, Expect, ] 문제 링크 정답 type ReplaceFirst = T extends [infer T1, ...infer Rest] ? T1 extends S ? [R, ...Rest] : [T1, ...ReplaceFirst] : [] 풀이 조건 T의 요소 중 처음 나오는 S를 R로 교체한 후 T를 반환한다. T에 S가 없는 경..
21220. PermutationsOfTuple 문제 Given a generic tuple type T extends unknown[], write a type which produces all permutations of T as a union. PermutationsOfTuple /** * Should return: * | [1, number, unknown] * | [1, unknown, number] * | [number, 1, unknown] * | [unknown, 1, number] * | [number, unknown, 1] * | [unknown, number ,1] */ cases type cases = [ Expect, Expect, Expect, Expect>, Expect>, ExpectFalse, ] 문제 링크 정답 type..
21106. Combs 문제 Combine multiple modifier keys, but the same modifier key combination cannot appear. In the ModifierKeys provided, the priority of the previous value is higher than the latter value; that is, cmd ctrl is OK, but ctrl cmd is not allowed. cases type ModifierKeys = ['cmd', 'ctrl', 'opt', 'fn'] type CaseTypeOne = 'cmd ctrl' | 'cmd opt' | 'cmd fn' | 'ctrl opt' | 'ctrl fn' | 'opt fn' type cases = [..
18220. Filter 문제 Implement the type Filter takes an Array T, primitive type or union primitive type Predicate and returns an Array include the elements of Predicate. cases type Falsy = false | 0 | '' | null | undefined type cases = [ Expect, Expect, Expect, ] 문제 링크 정답 type Filter = T extends [infer T1, ...infer Rest] ? T[0] extends P ? [T1, ...Filter] : Filter : [] 풀이 조건 P에 포함된 요소만 필터링해서 배열 형태로 출력한다. 해설 T의 요소..
18142. All 문제 Returns true if all elements of the list are equal to the second parameter passed in, false if there are any mismatches. type Test1 = [1, 1, 1] type Test2 = [1, 1, 2] type Todo = All // should be same as true type Todo2 = All // should be same as false cases type cases = [ Expect, Expect, Expect, Expect, Expect, Expect, Expect, Expect, Expect, Expect, Expect, Expect, Expect, Expect, Expect, ]..
16259. ToPrimitive 문제 Convert a property of type literal (label type) to a primitive type. type X = { name: 'Tom', age: 30, married: false, addr: { home: '123456', phone: '13111111111' }}type Expected = { name: string, age: number, married: boolean, addr: { home: string, phone: string }}type Todo = ToPrimitive // should be same as `Expected` cases type PersonInfo = { name: 'Tom' age: 30 married: false addr: { home..

728x90