Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2257 - MinusOne #2586

Open
Chen0x00 opened this issue Aug 11, 2021 · 0 comments
Open

2257 - MinusOne #2586

Chen0x00 opened this issue Aug 11, 2021 · 0 comments
Labels
2257 answer Share answers/solutions to a question en in English

Comments

@Chen0x00
Copy link

Chen0x00 commented Aug 11, 2021

type Digital = '0'|'1'|'2'|'3'|'4'|'5'|'6'|'7'|'8'|'9'
type MakeDigitalArray<
  N extends Digital,
  T extends any[] = []
> = N extends `${T['length']}` ? T : MakeDigitalArray<N, [...T, 0]>
type Multiply10<T extends any[]> = [...T,...T,...T,...T,...T,...T,...T,...T,...T,...T]

type ToArray<
  S extends number|string,
  T extends any[] = []
> = `${S}` extends `${infer F}${infer L}`
      ? F extends Digital
        ? ToArray<L, [...Multiply10<T>, ...MakeDigitalArray<F>]>
        : never
      : T

type Minus<
  S extends number,
  N extends number
> = ToArray<S> extends [...ToArray<N>, ...infer L] ? L['length'] : 0

type MinusOne<S extends number> = Minus<S, 1>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2257 answer Share answers/solutions to a question en in English
Projects
None yet
Development

No branches or pull requests

1 participant