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

#14078 - Modulo #14079

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

#14078 - Modulo #14079

wants to merge 1 commit into from

Conversation

github-actions[bot]
Copy link
Contributor

@github-actions github-actions bot commented Aug 5, 2022

This is an auto-generated PR that auto reflect on #14078, please go to #14078 for discussion or making changes.

Closes #14078

@github-actions github-actions bot mentioned this pull request Aug 5, 2022
@its-lee
Copy link
Contributor

its-lee commented Aug 5, 2022

Here's one way to do it:

type ToArray<N extends number, _Result extends number[] = []> =
  _Result extends { length: N }
  ? _Result
  : ToArray<N, [..._Result, any]>;

type Subtract<A extends any[], B extends any[]> =
  A extends [...infer C, ...B]
  ? C
  : never;

type ModulusOfArray<A extends any[], N extends any[]> =
  Subtract<A, N> extends never
  ? A['length']
  : ModulusOfArray<Subtract<A, N>, N>;

type Modulus<A extends number, N extends number> = ModulusOfArray<ToArray<A>, ToArray<N>>;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Modulo
1 participant