-
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.
- Loading branch information
Showing
4 changed files
with
151 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 |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
"aadamw", | ||
"Allis", | ||
"anthonyshew", | ||
"arguemnt", | ||
"ayrock", | ||
"ayush", | ||
"basokant", | ||
|
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,14 @@ | ||
# Santa's Remaining Deliveries | ||
|
||
Santa needs your help to count the number of presents he has to deliver! He's got all kinds of presents, from video game consoles (๐ฎ), stuffed animals (๐งธ), toy cars (๐๏ธ), books (๐), and more! | ||
|
||
We need a general purpose type that can take a tuple of items as its first arguemnt and an item to search for as the second argument. It should return a count of the item specified. | ||
|
||
For example: | ||
|
||
```ts | ||
Count<["๐", "๐", "๐ป", "๐ธ", "๐งฉ", "๐", "๐งธ"], "๐">; | ||
``` | ||
|
||
should return `3` because there are three `๐`. | ||
prompt by [Dimitri Mitropoulos](https://github.com/dimitropoulos) of [MiTS](https://www.youtube.com/@MichiganTypeScript) |
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,11 @@ | ||
type Count< | ||
List extends any[], | ||
Target extends string, | ||
Accumulator extends any[] = [] | ||
> = List extends [infer Current, ...infer Rest] | ||
? Current extends Target | ||
? Count<Rest, Target, [...Accumulator, Current]> | ||
: Count<Rest, Target, [...Accumulator]> | ||
: Accumulator["length"]; | ||
|
||
export { Count }; |
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,125 @@ | ||
import { Expect, Equal } from "type-testing"; | ||
import { Count } from "./solution"; | ||
|
||
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>>; |