Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.ja.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion README.ko.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion README.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion README.pt-BR.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion README.zh-CN.md

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions questions/34857-medium-defined-partial-record/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<!--info-header-start--><h1>Defined Partial Record <img src="https://img.shields.io/badge/-medium-d9901a" alt="medium"/> </h1><blockquote><p>by Aleksandr Trutanov <a href="https://github.com/alex-altay" target="_blank">@alex-altay</a></p></blockquote><p><a href="https://tsch.js.org/34857/play" target="_blank"><img src="https://img.shields.io/badge/-Take%20the%20Challenge-3178c6?logo=typescript&logoColor=white" alt="Take the Challenge"/></a> </p><!--info-header-end-->

### Defined Partial Record


Expand All @@ -24,3 +26,6 @@ const best: DefinedPartial<Record<'a' | 'b' | 'c', number>> = { a: 42 }
const sum = 0 + best.a // 42
const error = best.b // error: property 'b' does not exist on type '{ a: number; }'
```


<!--info-footer-start--><br><a href="../../README.md" target="_blank"><img src="https://img.shields.io/badge/-Back-grey" alt="Back"/></a> <a href="https://tsch.js.org/34857/answer" target="_blank"><img src="https://img.shields.io/badge/-Share%20your%20Solutions-teal" alt="Share your Solutions"/></a> <a href="https://tsch.js.org/34857/solutions" target="_blank"><img src="https://img.shields.io/badge/-Check%20out%20Solutions-de5a77?logo=awesome-lists&logoColor=white" alt="Check out Solutions"/></a> <!--info-footer-end-->
32 changes: 32 additions & 0 deletions questions/35300-medium-typing-game/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<!--info-header-start--><h1>Typing Game <img src="https://img.shields.io/badge/-medium-d9901a" alt="medium"/> <img src="https://img.shields.io/badge/-%23string-999" alt="#string"/> <img src="https://img.shields.io/badge/-%23game-999" alt="#game"/> <img src="https://img.shields.io/badge/-%23template--literal-999" alt="#template-literal"/></h1><blockquote><p>by ewdlop <a href="https://github.com/ewdlop" target="_blank">@ewdlop</a></p></blockquote><p><a href="https://tsch.js.org/35300/play" target="_blank"><img src="https://img.shields.io/badge/-Take%20the%20Challenge-3178c6?logo=typescript&logoColor=white" alt="Take the Challenge"/></a> </p><!--info-header-end-->

### Typing Game

Implement a type `TypingGame<Target, Typed>` that simulates a typing game. The type should return `true` if the `Typed` string exactly matches the `Target` string, and `false` otherwise.

In a typing game, players need to type out a target string exactly as shown. Your type should validate whether what the player typed matches the target perfectly.

#### Rules:
- The comparison is case-sensitive
- Spaces and special characters must match exactly
- The typed string must be exactly the same length as the target
- Empty strings are considered a match

#### Examples:

```ts
type Result1 = TypingGame<'hello', 'hello'> // true
type Result2 = TypingGame<'hello', 'hel'> // false (incomplete)
type Result3 = TypingGame<'hello', 'hallo'> // false (wrong character)
type Result4 = TypingGame<'', ''> // true (empty strings match)
```

This challenge tests your understanding of:
- String comparison in TypeScript's type system
- Template literal types
- Conditional types

Good luck, and happy typing! 🎮⌨️


<!--info-footer-start--><br><a href="../../README.md" target="_blank"><img src="https://img.shields.io/badge/-Back-grey" alt="Back"/></a> <a href="https://tsch.js.org/35300/answer" target="_blank"><img src="https://img.shields.io/badge/-Share%20your%20Solutions-teal" alt="Share your Solutions"/></a> <a href="https://tsch.js.org/35300/solutions" target="_blank"><img src="https://img.shields.io/badge/-Check%20out%20Solutions-de5a77?logo=awesome-lists&logoColor=white" alt="Check out Solutions"/></a> <!--info-footer-end-->
6 changes: 6 additions & 0 deletions questions/35300-medium-typing-game/info.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
difficulty: medium
title: Typing Game
tags: string, game, template-literal
author:
github: ewdlop
name: ewdlop
1 change: 1 addition & 0 deletions questions/35300-medium-typing-game/template.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
type TypingGame<Target extends string, Typed extends string> = any
42 changes: 42 additions & 0 deletions questions/35300-medium-typing-game/test-cases.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import type { Equal, Expect } from '@type-challenges/utils'

type cases = [
// Perfect match - all characters typed correctly
Expect<Equal<TypingGame<'hello', 'hello'>, true>>,

// Incomplete typing - not all characters typed yet
Expect<Equal<TypingGame<'hello', 'hel'>, false>>,

// Incorrect typing - wrong character
Expect<Equal<TypingGame<'hello', 'hallo'>, false>>,

// Empty strings
Expect<Equal<TypingGame<'', ''>, true>>,

// Empty typed, non-empty target
Expect<Equal<TypingGame<'hello', ''>, false>>,

// Typing more than target
Expect<Equal<TypingGame<'hello', 'hello world'>, false>>,

// Single character match
Expect<Equal<TypingGame<'a', 'a'>, true>>,

// Single character mismatch
Expect<Equal<TypingGame<'a', 'b'>, false>>,

// Numbers and special characters
Expect<Equal<TypingGame<'123', '123'>, true>>,
Expect<Equal<TypingGame<'test@123', 'test@123'>, true>>,

// Case sensitive
Expect<Equal<TypingGame<'Hello', 'hello'>, false>>,

// Spaces matter
Expect<Equal<TypingGame<'hello world', 'hello world'>, true>>,
Expect<Equal<TypingGame<'hello world', 'helloworld'>, false>>,

// Longer string
Expect<Equal<TypingGame<'The quick brown fox', 'The quick brown fox'>, true>>,
Expect<Equal<TypingGame<'The quick brown fox', 'The quick brown fo'>, false>>,
]