본문 바로가기

IT217

[typescript] ConstructorParameters<Type> 개념 constructor function의 파라미터의 type을 반환하는 Utility Type class A { constructor(b: number) { } } type T0 = ConstructorParameters; /** * * [b: number] * */ 2024. 3. 11.
[Typescript] Parameters<Type> 개념 함수의 파라마터의 Type을 Type으로 사용하고 싶을 때 function f1(arg: {a:number; b:string}) { } type T1 = Parameters /** * * [arg: { a:number; b:string }] * */ type T2 = Parameters[0] /** * * { a:number; b:string } * */ https://www.typescriptlang.org/docs/handbook/utility-types.html#parameterstype Documentation - Utility Types Types which are globally included in TypeScript www.typescriptlang.org 2024. 3. 11.
[data structure] Merge Sorting 개요 Insertion, Selection Sorting은 너무 느리다. 이유는 각각의 요소마다 비교하기 때문이다. worst time is at least nlog(n), usually quadratic n average time is also at least nlog(n), usually quadratic n Merge Sort와 Quick Sort의 average time is nlog(n)이므로 훨씬 빠르다. 방법 20개 숫자를 가지고 있는 컬렉션을 정렬해보기로 0 - 9 position에 있는 요소를 정렬 0 - 4 position에 있는 요소를 Insertion sort로 정렬 5 - 9 position에 있는 요소를 Insertion sort로 정렬 두 subarray를 합친다. (merge.. 2024. 3. 9.
[Data Structure] Selction Sorting Selection Sort 정렬 방법 가장 작은 요소를 찾고, 첫번째 위치에 지정. 범위 (0 ~ length) 가장 작은 요소를 찾고, 두번째 위치에 지정. 범위 (1 ~ length) 같은 방식으로 마지막 요소까지 진행 Time Complex 항상 quadratic in n not stable in-place sort worst space (n) is constant function sortBySelection(nums: number[]) { for (let i = 0; i nums[j]) { // find the smalles.. 2024. 3. 9.
[Data Structure] Insert Sorting Stable sort 같은 요소들의 순서가 보장되는 정렬 Time Complex Average time: n Worst time: n (important in ciritical systems) Space requirement: in-place sorts를 사용하면 최상의 케이스. in-place sorts 정렬하기 위해 컬랙션을 복사하지 않는 방법, 다른 변수를 사용하지 않거나 아니면 거의 사용하지 않거나 Insertion sort 요소를 처음부터 끝까지 읽으면서 정렬시키는 방법 첫번쨰 요소는 이미 정렬된 리스트를 갖는다. 두번째 요소를 가져와 첫번째 요소와 비교 후 조건에 따라 서로 교환한다. 세번째 요소를 가져와 두번째 요소와 비교 후 조건에 따라 서로 교환한다. 계속 같은 방법으로 끝까지 진행 Ti.. 2024. 3. 9.
[Typescript] Type-Only Imports and Export 개념 타입 표기와 선언에 사용될 선언만 import 한다. 완전히 제거되므로, 런타임에 남아 있는 것은 없다. import type { mapboxgl } from './mapboxgl' export type { mapboxgl } 특징 클래스는 런타임에 값을 가지고, 디자인-타임에 타입을 있으며 사용은 상황에 따라 다를 수 있다. import type을 사용하면, 확장 같은 것은 할 수 없다. import type { Component } from "react"; interface ButtonProps { // ... } class Button extends Component { // ~~~~~~~~~ // error! 'Component' only refers to a type, but is bein.. 2024. 3. 8.