• [Typescript] 31. Medium Length of String


    Compute the length of a string literal, which behaves like String#length.

    /* _____________ Your Code Here _____________ */
    
    type LengthOfString<S extends string, ACC extends any[] = []> = S extends '' ? ACC['length']: S extends `${infer First}${infer RT}` ? LengthOfString<RT, [...ACC, First]> : never;
    
    
    /* _____________ Test Cases _____________ */
    import type { Equal, Expect } from '@type-challenges/utils'
    
    type cases = [
      Expect<Equal<LengthOfString<''>, 0>>,
      Expect<Equal<LengthOfString<'kumiko'>, 6>>,
      Expect<Equal<LengthOfString<'reina'>, 5>>,
      Expect<Equal<LengthOfString<'Sound! Euphonium'>, 16>>,
    ]
  • 相关阅读:
    HTML和CSS 基本要点必看
    CSS
    六个选择器
    HTML初级课程 (自学可懂)
    this
    1.作用域链
    js if 语句
    js数据类型
    ifelse语句
    三元运算符
  • 原文地址:https://www.cnblogs.com/Answer1215/p/16693180.html
Copyright © 2020-2023  润新知