-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: rajput-hemant <rajput.hemant2001@gmail.com>
- Loading branch information
1 parent
47c26ca
commit c3ac00e
Showing
1 changed file
with
140 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
import { Equal, Expect } from "type-testing"; | ||
|
||
import { Increment } from "@/utils/type-helpers"; | ||
|
||
/* ----------------------------------------------------------------------------------------------- | ||
* Code here | ||
* -----------------------------------------------------------------------------------------------*/ | ||
|
||
type Count<T, E, C extends any[] = []> = T extends [infer S, ...infer R] | ||
? S extends E // if the current element is the element we're counting | ||
? Count<R, E, Increment<C>> // increment the count and recurse | ||
: Count<R, E, C> // otherwise, recurse for the rest of the array without incrementing | ||
: C["length"]; // if we've reached the end of the array, return the count | ||
|
||
/* ----------------------------------------------------------------------------------------------- | ||
* Do not edit below this line | ||
* -----------------------------------------------------------------------------------------------*/ | ||
|
||
type ToySack = [ | ||
"🎸", | ||
"🎧", | ||
"👟", | ||
"👟", | ||
"💻", | ||
"🪀", | ||
"🧩", | ||
"🎮", | ||
"🎨", | ||
"🕹️", | ||
"📱", | ||
"🧩", | ||
"🧸", | ||
"🎧", | ||
"👟", | ||
"🚲", | ||
"📚", | ||
"⌚", | ||
"🎨", | ||
"👟", | ||
"🎸", | ||
"🧸", | ||
"👟", | ||
"🎸", | ||
"📱", | ||
"🎧", | ||
"🎮", | ||
"🎒", | ||
"📱", | ||
"🧩", | ||
"🧩", | ||
"🚲", | ||
"🕹️", | ||
"🧵", | ||
"📱", | ||
"🕹️", | ||
"🕰️", | ||
"🧢", | ||
"🕹️", | ||
"👟", | ||
"🧸", | ||
"📚", | ||
"🧁", | ||
"🧩", | ||
"🎸", | ||
"🎮", | ||
"🧁", | ||
"📚", | ||
"💻", | ||
"⌚", | ||
"🛹", | ||
"🧁", | ||
"🧣", | ||
"🪁", | ||
"🎸", | ||
"🧸", | ||
"🧸", | ||
"🧸", | ||
"🧩", | ||
"🪁", | ||
"🏎️", | ||
"🏎️", | ||
"🧁", | ||
"📚", | ||
"🧸", | ||
"🕶️", | ||
"💻", | ||
"⌚", | ||
"⌚", | ||
"🕶️", | ||
"🎧", | ||
"🎧", | ||
"🎧", | ||
"💻", | ||
"👟", | ||
"🎸", | ||
"💻", | ||
"🪐", | ||
"📚", | ||
"🎨", | ||
"📱", | ||
"🎧", | ||
"📱", | ||
"🎸", | ||
"🏎️", | ||
"👟", | ||
"🚲", | ||
"📱", | ||
"🚲", | ||
"🎸", | ||
]; | ||
|
||
type test_0_actual = Count<ToySack, "👟">; | ||
// ^? | ||
type test_0_expected = 8; | ||
type test_0 = Expect<Equal<test_0_expected, test_0_actual>>; | ||
|
||
type test_1_actual = Count<ToySack, "🧦">; | ||
// ^? | ||
type test_1_expected = 0; | ||
type test_1 = Expect<Equal<test_1_expected, test_1_actual>>; | ||
|
||
type test_2_actual = Count<ToySack, "🧩">; | ||
// ^? | ||
type test_2_expected = 6; | ||
type test_2 = Expect<Equal<test_2_expected, test_2_actual>>; | ||
|
||
type test_3_actual = Count<ToySack, "🛹">; | ||
// ^? | ||
type test_3_expected = 1; | ||
type test_3 = Expect<Equal<test_3_expected, test_3_actual>>; | ||
|
||
type test_4_actual = Count<ToySack, "🏎️">; | ||
// ^? | ||
type test_4_expected = 3; | ||
type test_4 = Expect<Equal<test_4_expected, test_4_actual>>; | ||
|
||
type test_5_actual = Count<ToySack, "📚">; | ||
// ^? | ||
type test_5_expected = 5; | ||
type test_5 = Expect<Equal<test_5_expected, test_5_actual>>; |