A collection of TypeScript problem-solving exercises completed during a conceptual TypeScript session.
This project focuses on practicing important TypeScript concepts such as type annotations, interfaces, union types, arrays, functions, conditional logic, and object handling.
This project contains solutions for the following 9 TypeScript problems:
Determines the ticket price based on a person's age.
Concepts used:
- Function parameters
- Type annotations
- Conditional statements
- Return types
Checks the available stock quantity and returns an appropriate stock status.
Examples include:
- Out of Stock
- Almost Sold Out
- Available
- In Stock
Concepts used:
- Conditional statements
- Comparison operators
- Function return types
Uses a User interface to format user information into a readable profile message.
User information includes:
- Name
- Age
- City
Concepts used:
- Interfaces
- Object types
- Functions
- Template literals
Calculates the total price of products inside a shopping cart.
Each product contains:
- Name
- Price
The solution uses the reduce() method to calculate the total.
Concepts used:
- Arrays
- Object types
reduce()- Type annotations
Calculates a student's average marks and determines whether the student has passed or failed.
The returned result includes:
- Student name
- Average marks
- Result status
Concepts used:
- Interfaces
- Arrays
reduce()- Conditional logic
- Object return types
Checks whether a user role has permission to edit.
Available roles include:
admineditorviewer
Concepts used:
- Union types
- Boolean return values
- Conditional logic
Finds products based on a selected category.
The solution uses the filter() method to return matching products.
Concepts used:
- Interfaces
- Arrays
filter()- Function parameters
Determines the status of different types of patients.
Patient types include:
- General patient
- Emergency patient
Emergency patients also include different emergency levels.
Concepts used:
- Interfaces
- Union types
- Type narrowing
- Conditional statements
Processes banking transactions such as:
- Deposit
- Withdrawal
The function also checks whether the account has sufficient funds for a withdrawal.
Concepts used:
- Union types
- Object types
- Conditional logic
- Multiple return types
This project demonstrates the use of:
- Type annotations
- Function parameter types
- Function return types
- Interfaces
- Union types
- Arrays
- Objects
- Conditional statements
- Template literals
reduce()filter()- Type narrowing
- Boolean values
- TypeScript configuration
ts-problem/
│
├── src/
│ ├── 1.getTicketPrice.ts
│ ├── 2.getStockStatus.ts
│ ├── 3.formatUserProfile.ts
│ ├── 4.calculateCartTotal.ts
│ ├── 5.getStudentResult.ts
│ ├── 6.canEdit.ts
│ ├── 7.findProducts.ts
│ ├── 8.getPatientStatus.ts
│ ├── 9.processTransactions.ts
│ └── hello.ts
│
├── dist/
│
└── tsconfig.json