반응형

분류 전체보기 723

[TS] type-challenges: 14. First of Array

문제 배열(튜플) T를 받아 첫 원소의 타입을 반환하는 제네릭 First를 구현하세요. type arr1 = ['a', 'b', 'c'] type arr2 = [3, 2, 1] type head1 = First // expected to be 'a' type head2 = First // expected to be 3 풀이 비교적 간단한 문제라서 T[0]을 반환하도록 했는데, 그랬더니 []인경우 never에 대한 케이스에 걸려서 분기처리를 진행해줬다 type First = T extends [] ? never : T[0]; 출처 https://github.com/type-challenges/type-challenges/blob/main/questions/00014-easy-first/README.ko.m..

[TS] TypeScript Exercises 3 해석 및 풀이

Intro Since we already have some of the additional information about our users, it's a good idea to output it in a nice way. 이미 유저의 추가적인 정보를 알고 있기 때문에, 멋진 방법으로 이를 표출하면 좋을 것 같다 Exercise Fix type errors in logPerson function. logPerson function should accept both User and Admin and should output relevant information according to the input: occupation for User and role for Admin. logPerson 함수의 타입에러..

[TS] type-challenges : 11. Tuple to Object

문제 배열(튜플)을 받아, 각 원소의 값을 key/value로 갖는 오브젝트 타입을 반환하는 타입을 구현하세요. 예시 const tuple = ['tesla', 'model 3', 'model X', 'model Y'] as const type result = TupleToObject // expected { tesla: 'tesla', 'model 3': 'model 3', 'model X': 'model X', 'model Y': 'model Y'} 풀이 객체의 키도, 값도 T배열의 요소기 때문에 키값 kv가 T[number]에 속해있고 이 것이 키인 동시에 값이라고 명시해주면 해결된다. 이때 T는 string 또는 number 가 포함된 배열이라는 점도 명시해준다. type TupleToObject..

[TS] TypeScript Exercises 2 해석 및 풀이

Introduce All 2 users liked the idea of the community. We should go forward and introduce some order. We are in Germany after all. Let's add a couple of admins. Initially, we only had users in the in-memory database. After introducing Admins, we need to fix the types so that everything works well together. 두명의 유저 전부 커뮤니티의 아이디어가 마음에 들었고, 우리는 이제 소개를 해야합니다. admin 몇명을 추가해봅시다. 처음에 우리는 데이터베이스에만 유저를 저장..

[TS] TypeScript Exercises 1 해석 및 풀이

Introduce We are starting a small community of users. For performance reasons we have decided to store all users right in the code. This way we can provide our developers with more user-interaction opportunities. With user-related data, at least. All the GDPR-related issues will be solved some other day. This would be the basis for our future experiments during these exercises. 우리는 이제 유저들을 위한 작은..

[TS] type-challenges : 7. Readonly

문제 T의 모든 프로퍼티를 읽기 전용(재할당 불가)으로 바꾸는 내장 제네릭 Readonly를 이를 사용하지 않고 구현하세요. 예시: interface Todo { title: string description: string } const todo: MyReadonly = { title: "Hey", description: "foobar" } todo.title = "Hello" // Error: cannot reassign a readonly property todo.description = "barFoo" // Error: cannot reassign a readonly property 풀이 type MyReadonly = {readonly [key in keyof T]: T[key]} 출처 https..

[TS] type-challenges : 4. Pick

문제 T에서 K 프로퍼티만 선택해 새로운 오브젝트 타입을 만드는 내장 제네릭 Pick을 이를 사용하지 않고 구현하세요. 예시: interface Todo { title: string description: string completed: boolean } type TodoPreview = MyPick const todo: TodoPreview = { title: 'Clean room', completed: false, } 풀이 type MyPick = {[key in K]: T[key]}; 출처 https://github.com/type-challenges/type-challenges/blob/main/questions/00004-easy-pick/README.ko.md GitHub - type-chal..

[TS] type-challenges : 13. Hello World

문제 Hello, World! Type Challenges에서는 타입 단언(assertion)을 하기 위해 자체적인 타입 시스템을 사용합니다. 이 과제에서는, 아래의 코드를 변경해서 테스트 코드를 통과하세요. (타입 체크 에러 없음). // string이 되어야 합니다. type HelloWorld = any // 아래의 테스트가 통과하도록 만드세요. type test = Expect Take the Challenge 버튼을 클릭해서 코딩을 시작하세요! Happy Hacking! 풀이 /* _____________ 여기에 코드 입력 _____________ */ type HelloWorld = string // expected to be a string /* _____________ 테스트 케이스 ___..

[프로그래머스][SQL] 저자 별 카테고리 별 매출액 집계하기

https://school.programmers.co.kr/learn/courses/30/lessons/144856 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 2022년 1월의 도서 판매 데이터를 기준으로 저자 별, 카테고리 별 매출액(TOTAL_SALES = 판매량 * 판매가) 을 구하여, 저자 ID(AUTHOR_ID), 저자명(AUTHOR_NAME), 카테고리(CATEGORY), 매출액(SALES) 리스트를 출력하는 SQL문을 작성해주세요. 결과는 저자 ID를 오름차순으로, 저자 ID가 같다면 카테고리를 내림차순 정렬해주세요. select b.au..

[프로그래머스][SQL] 주문량이 많은 아이스크림들 조회하기

https://school.programmers.co.kr/learn/courses/30/lessons/133027 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 문제 7월 아이스크림 총 주문량과 상반기의 아이스크림 총 주문량을 더한 값이 큰 순서대로 상위 3개의 맛을 조회하는 SQL 문을 작성해주세요 놓치면 안되는 조건 ** 7월에는 아이스크림 주문량이 많아 같은 아이스크림에 대하여 서로 다른 두 공장에서 아이스크림 가게로 출하를 진행하는 경우가 있습니다. 이 경우 같은 맛의 아이스크림이라도 다른 출하 번호를 갖게 됩니다. 풀이 -- 코드를 입력하세요 ..

반응형