首页 > 其他分享 >[Typescript] 71. Medium - Trunc

[Typescript] 71. Medium - Trunc

时间:2022-10-27 14:34:21浏览次数:44  
标签:Typescript _____________ number Medium Expect 71 NUM type Trunc

Implement the type version of Math.trunc, which takes string or number and returns the integer part of a number by removing any fractional digits.

For example:

type A = Trunc<12.34> // 12
/* _____________ Your Code Here _____________ */

type Trunc<N extends number | string> = `${N}` extends `${infer NUM}.${infer _}`
  ? `${NUM}`
  : `${N}`;


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

type cases = [
  Expect<Equal<Trunc<0.1>, '0'>>,
  Expect<Equal<Trunc<1.234>, '1'>>,
  Expect<Equal<Trunc<12.345>, '12'>>,
  Expect<Equal<Trunc<-5.1>, '-5'>>,
  Expect<Equal<Trunc<'1.234'>, '1'>>,
  Expect<Equal<Trunc<'-10.234'>, '-10'>>,
  Expect<Equal<Trunc<10>, '10'>>,
]

 

标签:Typescript,_____________,number,Medium,Expect,71,NUM,type,Trunc
From: https://www.cnblogs.com/Answer1215/p/16832136.html

相关文章

  • TypeScript 复习与进阶三部曲 (2) – 把 TypeScript 当编程语言使用
    前言上一篇,我们提到,TypeScript进阶有3个阶段. 第一阶段是"把TypeScript当强类型语言使用",我们已经介绍完了. 第二阶段是"把TypeScript当编程语言使用"......
  • [Typescript] 70. Medium - Without
    ImplementthetypeversionofLodash.without,Without<T,U>takesanArrayT,numberorarrayUandreturnsanArraywithouttheelementsofU.typeRes=With......
  • [Typescript] 69. Medium - Trim Right
    Implement TrimRight<T> whichtakesanexactstringtypeandreturnsanewstringwiththewhitespaceendingremoved.Forexample:typeTrimed=TrimRight<'......
  • Codeforces Round #715 (Div. 2) C
    C.TheSportsFestival观察发现我们显然选择一个数字开始后我们拿周围的数字显然存在最优解(sort过)这样就很金典了n=2000我们显然可以暴力区间dp然后将转移只用从拿......
  • [Typescript] 68. Medium - Fill
    Fill,acommonJavaScriptfunction,nowletusimplementitwithtypes. Fill<T,N,Start?,End?>,asyoucansee,Fill acceptsfourtypesofparameters,ofwh......
  • AcWing 271杨老师的照相排列
    思路\(1=<k<=5\),所以最多会有五个位置,五个位置分配人,即集合为f[a][b][c][d][e]表示五个位置各放了a,b,c,d,e个人的方法的数量,同时h[1]>=h[2]>=h[3]>=h[4]>=h[5],所......
  • #yyds干货盘点#初聊typescript
    一、认识Typescript(1)Javascript是一种动态类型的弱类型语言Javascript超集:A.包含与兼容所有JS特性,支持共存B.支持渐进式引入与升级(2)TypeScript是一种静态类型的弱类型......
  • HDU 1712 ACboy needs your help
    题目链接:​​传送门​​题面:ACboyneedsyourhelpProblemDescriptionACboyhasNcoursesthisterm,andheplanstospendatmostMdaysonstudy.Ofcourse,the......
  • HDU 1171 Big Event In HDU
    题目链接:​​传送门​​BigEventinHDUProblemDescriptionNowadays,weallknowthatComputerCollegeisthebiggestdepartmentinHDU.But,maybeyoudon’t......
  • Luogu P4171 [JSOI2010]满汉全席
    题目链接:​​传送门​​2-sat板子题注意输入的时候可不要以为w和h后面数字只有一位*/#include<iostream>#include<cstdio>#include<cstring>#include<cstdlib>#includ......