Skip to content

Commit 3d00d4d

Browse files
committed
feat: add new function exercises and enhance documentation
- Introduced new exercises on function declarations, parameters, and returns, including solutions and tests. - Updated README files to provide clearer instructions and learning objectives. - Added JSDoc comments to enhance code clarity and IDE support for functions. - Removed outdated exercises and corresponding files to streamline the learning path. - Updated package-lock.json to reflect changes in dependencies.
1 parent d8f19fd commit 3d00d4d

45 files changed

Lines changed: 199 additions & 54 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 19 additions & 0 deletions
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Function Declarations
2+
// A named function that returns a value
3+
4+
// 🐨 Create a function named `getMessage` that returns "Hello, functions!"
5+
// Make sure to add an explicit return type of string.
6+
7+
// ✅ Test your function
8+
// console.log(getMessage()) // "Hello, functions!"
9+
10+
// 🐨 Export your function so we can verify your work
11+
// export { getMessage }
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"name": "exercises_05.functions_01.problem.function-declaration",
3+
"type": "module",
4+
"scripts": {
5+
"start": "npx @kentcdodds/log-module ./index.ts",
6+
"start:watch": "npx @kentcdodds/log-module --watch ./index.ts",
7+
"test": "node --test index.test.ts",
8+
"test:watch": "node --watch --test index.test.ts"
9+
}
10+
}
Lines changed: 7 additions & 0 deletions
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import assert from 'node:assert/strict'
2+
import { test } from 'node:test'
3+
import * as solution from './index.ts'
4+
5+
await test('getMessage is exported', () => {
6+
assert.ok(
7+
'getMessage' in solution,
8+
'🚨 Make sure you export "getMessage" - add: export { getMessage }',
9+
)
10+
})
11+
12+
await test('getMessage returns the expected message', () => {
13+
assert.strictEqual(
14+
solution.getMessage(),
15+
'Hello, functions!',
16+
'🚨 getMessage() should return "Hello, functions!"',
17+
)
18+
})
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Function Declarations
2+
// A named function that returns a value
3+
4+
function getMessage(): string {
5+
return 'Hello, functions!'
6+
}
7+
8+
// ✅ Test your function
9+
console.log(getMessage()) // "Hello, functions!"
10+
11+
export { getMessage }
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"name": "exercises_05.functions_01.solution.function-declaration",
3+
"type": "module",
4+
"scripts": {
5+
"start": "npx @kentcdodds/log-module ./index.ts",
6+
"start:watch": "npx @kentcdodds/log-module --watch ./index.ts",
7+
"test": "node --test index.test.ts",
8+
"test:watch": "node --watch --test index.test.ts"
9+
}
10+
}

exercises/05.functions/01.problem.parameters-and-returns/README.mdx renamed to exercises/05.functions/02.problem.parameters-and-returns/README.mdx

Lines changed: 6 additions & 3 deletions

exercises/05.functions/01.problem.parameters-and-returns/index.ts renamed to exercises/05.functions/02.problem.parameters-and-returns/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// E-commerce Utility Functions
2-
// Creating functions with typed parameters and returns
2+
// Creating functions with typed parameters and return values
33

44
// 🐨 Create a function `calculateTax` that:
55
// - Takes `amount` (number) and `rate` (number)

exercises/05.functions/01.problem.parameters-and-returns/package.json renamed to exercises/05.functions/02.problem.parameters-and-returns/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "exercises_05.functions_01.problem.parameters-and-returns",
2+
"name": "exercises_05.functions_02.problem.parameters-and-returns",
33
"type": "module",
44
"scripts": {
55
"start": "npx @kentcdodds/log-module ./index.ts",

0 commit comments

Comments
 (0)