Created
December 20, 2023 10:45
-
-
Save mhdcodes/ef0f12aeddcde12a8df04cefc5957166 to your computer and use it in GitHub Desktop.
Typescript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import type { Subtract, Compare } from 'ts-arithmetic'; | |
| import type { Equal, Expect } from '@type-challenges/utils' | |
| type Modulo<N1 extends number, Bound extends number> = Compare<Bound, N1> extends 0 | |
| ? 0 | |
| : Compare<Bound, N1> extends 1 ? N1 : Subtract<N1, Bound> | |
| /* _____________ Test Cases _____________ */ | |
| type cases = [ | |
| Expect<Equal<Modulo<0, 3>, 0>>, | |
| Expect<Equal<Modulo<1, 3>, 1>>, | |
| Expect<Equal<Modulo<2, 3>, 2>>, | |
| Expect<Equal<Modulo<3, 3>, 0>>, | |
| Expect<Equal<Modulo<4, 3>, 1>>, | |
| ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment