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 #33253

Open
huangxinrui opened this issue May 15, 2024 · 0 comments
Open

2257 - MinusOne #33253

huangxinrui opened this issue May 15, 2024 · 0 comments
Labels
2257 answer Share answers/solutions to a question zh-CN 简体中文

Comments

@huangxinrui
Copy link

type NumberList = [9, 0, 1, 2, 3, 4, 5, 6, 7, 8];
type ReverseStr<T extends string | number> = (T extends string ? T : ${T}) extends ${infer L}${infer R}
? ${ReverseStr<R>}${L}
: T;
type RemoveFirstZero = T extends ${infer L}${infer R}
? L extends '0'
? R extends ''
? ${T}
: ${RemoveFirstZero<R>}
: T
: never;
type Parse2Int = T extends any
? RemoveFirstZero extends ${infer N extends number}
? N
: never
: never;
type LoopStr = T extends ${infer L extends number}${infer R}
? L extends 0
? ${NumberList[L]}${LoopStr<R>}
: ${NumberList[L]}${R}
: '';
type MinusOne = T extends 0 ? -1 : Parse2Int<ReverseStr<LoopStr<ReverseStr>>>;

@huangxinrui huangxinrui added answer Share answers/solutions to a question zh-CN 简体中文 labels May 15, 2024
@github-actions github-actions bot added the 2257 label May 15, 2024
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 zh-CN 简体中文
Projects
None yet
Development

No branches or pull requests

1 participant