Skip to content
New issue

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

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

Already on GitHub? # to your account

type-challenges-solutions/en/medium-absolute #348

Open
r2abreu opened this issue Oct 12, 2024 · 1 comment
Open

type-challenges-solutions/en/medium-absolute #348

r2abreu opened this issue Oct 12, 2024 · 1 comment

Comments

@r2abreu
Copy link

r2abreu commented Oct 12, 2024

I really like the original solution.

Here's a more verbose one:

type RemoveNegativeSign<T extends string> = T extends `${infer First}${infer Rest}` 
  ? First extends "-" 
    ? Rest 
    : T 
  : never

type Absolute<T extends number | string | bigint> = RemoveNegativeSign<`${T}`>
Copy link
Author

r2abreu commented Oct 12, 2024

I really like the original solution.

Here's a more verbose one:

type RemoveNegativeSign<T extends string> = T extends `${infer First}${infer Rest}` 
  ? First extends "-" 
    ? Rest 
    : T 
  : never

type Absolute<T extends number | string | bigint> = RemoveNegativeSign<`${T}`>

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant