-
Notifications
You must be signed in to change notification settings - Fork 0
/
4425-greater-than.ts
51 lines (38 loc) · 1.45 KB
/
4425-greater-than.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*
4425 - Greater Than
-------
by ch3cknull (@ch3cknull) #medium #array
### Question
In This Challenge, You should implement a type `GreaterThan<T, U>` like `T > U`
Negative numbers do not need to be considered.
For example
```ts
GreaterThan<2, 1> //should be true
GreaterThan<1, 1> //should be false
GreaterThan<10, 100> //should be false
GreaterThan<111, 11> //should be true
```
Good Luck!
> View on GitHub: https://tsch.js.org/4425
*/
/* _____________ Your Code Here _____________ */
type ArrayWithLength<T extends number, U extends any[] = []> = U['length'] extends T ? U : ArrayWithLength<T, [true, ...U]>;
type GreaterThan<T extends number, U extends number> = ArrayWithLength<U> extends [...ArrayWithLength<T>, ...infer _] ? false : true;
/* _____________ Test Cases _____________ */
import type { Equal, Expect } from '@type-challenges/utils'
type cases = [
Expect<Equal<GreaterThan<1, 0>, true>>,
Expect<Equal<GreaterThan<5, 4>, true>>,
Expect<Equal<GreaterThan<4, 5>, false>>,
Expect<Equal<GreaterThan<0, 0>, false>>,
Expect<Equal<GreaterThan<10, 9>, true>>,
Expect<Equal<GreaterThan<20, 20>, false>>,
Expect<Equal<GreaterThan<10, 100>, false>>,
Expect<Equal<GreaterThan<111, 11>, true>>,
]
/* _____________ Further Steps _____________ */
/*
> Share your solutions: https://tsch.js.org/4425/answer
> View solutions: https://tsch.js.org/4425/solutions
> More Challenges: https://tsch.js.org
*/