Po_tta_tt0
콩심콩 팥심팥 🌱
Po_tta_tt0
전체 방문자
오늘
어제
  • 분류 전체보기 (266)
    • 🐛 회고 (14)
    • 💭 생각 (2)
    • 🤸‍♀️ 내 프로젝트 (16)
      • FISH-NEWS (8)
      • MBTI 과몰입 테스트 (2)
      • twitter clonecoding with TS (4)
      • pilzagenda (2)
    • 👨‍👩‍👧‍👦 팀 프로젝트 (2)
      • 피우다 프로젝트 (0)
      • SEMO(세상의 모든 모임) (1)
      • 마음을 전하는 텃밭 (1)
      • Stackticon (0)
    • 👨‍💻 CS지식 (11)
    • ✍ 공부 (94)
      • JavaScript (21)
      • TypeScript (39)
      • Html (0)
      • CSS (2)
      • React (18)
      • NextJS (7)
      • Vue (1)
      • Python (1)
      • Django (0)
      • 개발환경 & 그 외 (2)
    • 🏄‍♀️ 코딩테스트 (99)
      • 🐍 Python (99)
    • 🐙 Git & GitHub (3)
    • 📑 오류기록 (8)
    • 📚 우리를 위한 기록 (9)
    • 수업 (3)
    • 강의 등 (2)
    • 👩‍🎓 SSAFY (0)
    • 👋 우테코 (0)

블로그 메뉴

  • 홈
  • 태그

공지사항

인기 글

태그

  • 문자열
  • Next.js
  • BFS + DP
  • 백준 숨바꼭질
  • 시뮬레이션
  • 플로이드 워셜
  • 백준
  • dfs
  • 파이썬 다익스트라
  • React
  • react-router-dom
  • js
  • bfs
  • 자바스크립트
  • 이분탐색
  • 파이썬 감시 피하기
  • 구현
  • 파이썬
  • 백준 파이썬
  • DP

최근 댓글

최근 글

티스토리

hELLO · Designed By 정상우.
Po_tta_tt0

콩심콩 팥심팥 🌱

✍ 공부/TypeScript

[type-challenges] Absolute

2023. 6. 27. 08:00
반응형

문제

number, string 혹은 bigint를 받는 Absolute 타입을 만드시오

output은 양의 정수 string입니다

설명

/* _____________ Your Code Here _____________ */

type Absolute<T extends number | string | bigint> = `${T}` extends `${'-'}${infer P}`? P :`${T}`

/* _____________ Test Cases _____________ */
import type { Equal, Expect } from '@type-challenges/utils'

type t = Absolute<-1_000_000n>

type cases = [
  Expect<Equal<Absolute<0>, '0'>>,
  Expect<Equal<Absolute<-0>, '0'>>,
  Expect<Equal<Absolute<10>, '10'>>,
  Expect<Equal<Absolute<-5>, '5'>>,
  Expect<Equal<Absolute<'0'>, '0'>>,
  Expect<Equal<Absolute<'-0'>, '0'>>,
  Expect<Equal<Absolute<'10'>, '10'>>,
  Expect<Equal<Absolute<'-5'>, '5'>>,
  Expect<Equal<Absolute<-1_000_000n>, '1000000'>>,
  Expect<Equal<Absolute<9_999n>, '9999'>>,
]

Expect<Equal<Absolute<-1_000_000n>, '1000000'>>,
이게 어려웠다

type Absolute<T extends number | string | bigint> = T
이렇게만 해도 언더바는 사라지고

type Absolute<T extends number | string | bigint> =${T}
이렇게 하면 n도 사라진다 맨 끝에 n을 붙히는게 bigint라서 사라지는 것 같다
이런 이해가 없으면 나처럼 -, _, n 을 다 처리하려고 하게 될지도 모른다

반응형
저작자표시 (새창열림)

'✍ 공부 > TypeScript' 카테고리의 다른 글

[type-challenges] Merge  (0) 2023.06.27
[type-challenges] String to Union  (0) 2023.06.27
[type-challenges] Append to object  (0) 2023.06.27
[type-challenges] Flatten  (0) 2023.06.26
[type-challenges] Length of String  (0) 2023.06.26
    '✍ 공부/TypeScript' 카테고리의 다른 글
    • [type-challenges] Merge
    • [type-challenges] String to Union
    • [type-challenges] Append to object
    • [type-challenges] Flatten
    Po_tta_tt0
    Po_tta_tt0
    감자의 코딩하는 블로그 콩심은데 콩나고 팥심은데 팥난다

    티스토리툴바