Typescript-exercises 12

hotbreakb·2022년 6월 13일
1

typescript-exercises

목록 보기
12/12

문제

데이터베이스에 useradmin이 많다. CEO의 아빠 제프는 회사가 빅데이터 스타트업이라고 말하며 통계와 분석이 필요하다고 했다.

설문조사를 진행했다. 결과는 4가지로 이루어져 있다. 스택오버플로우에 있는 stats 모듈을 사용할 것이다. declare 해보자.

코드

타입을 하나씩 적어야 하나 고민했는데 공통적인 특징이 있었다.

🔻 공식적인 답안

declare module 'stats' {
    type Comparator<T> = (a: T, b: T) => number;

    type GetIndex = <T>(input: T[], comparator: Comparator<T>) => number;
    export const getMaxIndex: GetIndex;
    export const getMinIndex: GetIndex;
    export const getMedianIndex: GetIndex;

    type GetElement = <T>(input: T[], comparator: Comparator<T>) => T | null;
    export const getMaxElement: GetElement;
    export const getMinElement: GetElement;
    export const getMedianElement: GetElement;

    export const getAverageValue: <T>(input: T[], getValue: (item: T) => number) => number | null;
}
profile
글쟁이 프론트 개발자, 헬렌입니다.

0개의 댓글