-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday12.ts
30 lines (24 loc) · 1.11 KB
/
day12.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
/*Solution*/
type FindSanta<T extends any[]> = T extends [...infer A, infer B] ? (B extends "🎅🏼" ? A["length"] : FindSanta<A>) : never;
/*Tests*/
import { Expect, Equal } from "type-testing";
type Forest0 = ["🎅🏼", "🎄", "🎄", "🎄"];
type test_0_actual = FindSanta<Forest0>;
type test_0_expected = 0;
type test_0 = Expect<Equal<test_0_expected, test_0_actual>>;
type Forest1 = ["🎄", "🎅🏼", "🎄", "🎄", "🎄", "🎄"];
type test_1_actual = FindSanta<Forest1>;
type test_1_expected = 1;
type test_1 = Expect<Equal<test_1_expected, test_1_actual>>;
type Forest2 = ["🎄", "🎄", "🎅🏼", "🎄"];
type test_2_actual = FindSanta<Forest2>;
type test_2_expected = 2;
type test_2 = Expect<Equal<test_2_expected, test_2_actual>>;
type Forest3 = ["🎄", "🎄", "🎄", "🎅🏼", "🎄"];
type test_3_actual = FindSanta<Forest3>;
type test_3_expected = 3;
type test_3 = Expect<Equal<test_3_expected, test_3_actual>>;
type Forest4 = ["🎄", "🎄", "🎄", "🎄"];
type test_4_actual = FindSanta<Forest4>;
type test_4_expected = never;
type test_4 = Expect<Equal<test_4_expected, test_4_actual>>;