Skip to content

Commit d65fd63

Browse files
committed
fix: use Array<T> syntax consistently in exercises
- Changed array type annotations from `type[]` to `Array<type>` in problem files - Updated solution files to match - Added note in never-type exercise explaining generics will be covered later This ensures consistency between problem hints and solutions, reducing learner confusion.
1 parent c883c0c commit d65fd63

File tree

6 files changed

+8
-6
lines changed
  • exercises
    • 02.variables/02.problem.reassignment-vs-mutation
    • 03.control-flow
    • 04.functions
    • 05.void-and-never/02.problem.never-type

6 files changed

+8
-6
lines changed

exercises/02.variables/02.problem.reassignment-vs-mutation/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Understanding Reassignment vs Mutation
22

33
// This array is declared with const
4-
const shoppingList: string[] = ['milk', 'eggs', 'bread']
4+
const shoppingList: Array<string> = ['milk', 'eggs', 'bread']
55

66
console.log('Original list:', shoppingList)
77

exercises/03.control-flow/02.problem.loops/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Shopping Cart Calculator
22
// Using loops to process arrays
33

4-
const prices: number[] = [29.99, 9.99, 49.99, 4.99, 19.99]
4+
const prices: Array<number> = [29.99, 9.99, 49.99, 4.99, 19.99]
55

66
// 🐨 Create a variable `total` starting at 0
77
// 💰 let total = 0

exercises/03.control-flow/03.problem.for-of-iteration/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Shopping Cart Analysis
22
// Using for...of for cleaner iteration
33

4-
const prices: number[] = [29.99, 9.99, 49.99, 4.99, 19.99]
4+
const prices: Array<number> = [29.99, 9.99, 49.99, 4.99, 19.99]
55

66
// 🐨 Create variables for total, count, and highest price
77
// let total = 0

exercises/04.functions/04.problem.arrow-functions/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function greet(name: string): string {
1212
}
1313

1414
// 🐨 Convert this to an arrow function (keep the explicit return - it has multiple lines)
15-
function calculateTotal(prices: number[], taxRate: number): number {
15+
function calculateTotal(prices: Array<number>, taxRate: number): number {
1616
const subtotal = prices.reduce((sum, price) => sum + price, 0)
1717
const tax = subtotal * taxRate
1818
return subtotal + tax

exercises/04.functions/04.solution.arrow-functions/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const double = (n: number) => n * 2
88
const greet = (name: string) => `Hello, ${name}!`
99

1010
// Arrow function with explicit return (multiple lines)
11-
const calculateTotal = (prices: number[], taxRate: number) => {
11+
const calculateTotal = (prices: Array<number>, taxRate: number) => {
1212
const subtotal = prices.reduce((sum, price) => sum + price, 0)
1313
const tax = subtotal * taxRate
1414
return subtotal + tax
@@ -18,7 +18,7 @@ const calculateTotal = (prices: number[], taxRate: number) => {
1818
const isEven = (n: number) => n % 2 === 0
1919

2020
// Function using arrow function callbacks
21-
function processNumbers(numbers: number[]) {
21+
function processNumbers(numbers: Array<number>) {
2222
return {
2323
doubled: numbers.map((n) => n * 2),
2424
evens: numbers.filter((n) => n % 2 === 0),

exercises/05.void-and-never/02.problem.never-type/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
// 🐨 Create `assertNonNull` that takes a value of type T | null
1111
// If null, throw an error. Otherwise, return the value.
1212
// 💰 function assertNonNull<T>(value: T | null, message: string): T
13+
// 🦉 Note: The <T> syntax is called "generics" - we'll cover this in detail
14+
// in the Type Safety workshop. For now, just follow the pattern above.
1315

1416
// Example of exhaustiveness checking
1517
type Status = 'pending' | 'success' | 'error'

0 commit comments

Comments
 (0)