Correct mistakes

This commit is contained in:
cediackermann 2026-05-18 08:18:00 +02:00
parent 7afc27e1cd
commit 767346f408
5 changed files with 73 additions and 6 deletions

40
.vscode/launch.json vendored
View file

@ -19,6 +19,46 @@
"target": "m323", "target": "m323",
"configuration": "release", "configuration": "release",
"preLaunchTask": "swift: Build Release m323" "preLaunchTask": "swift: Build Release m323"
},
{
"type": "swift",
"request": "launch",
"args": [],
"cwd": "${workspaceFolder:m323}",
"name": "Debug WeDontLikeCharA",
"target": "WeDontLikeCharA",
"configuration": "debug",
"preLaunchTask": "swift: Build Debug WeDontLikeCharA"
},
{
"type": "swift",
"request": "launch",
"args": [],
"cwd": "${workspaceFolder:m323}",
"name": "Release WeDontLikeCharA",
"target": "WeDontLikeCharA",
"configuration": "release",
"preLaunchTask": "swift: Build Release WeDontLikeCharA"
},
{
"type": "swift",
"request": "launch",
"args": [],
"cwd": "${workspaceFolder:m323}",
"name": "Debug Aufgabe3",
"target": "Aufgabe3",
"configuration": "debug",
"preLaunchTask": "swift: Build Debug Aufgabe3"
},
{
"type": "swift",
"request": "launch",
"args": [],
"cwd": "${workspaceFolder:m323}",
"name": "Release Aufgabe3",
"target": "Aufgabe3",
"configuration": "release",
"preLaunchTask": "swift: Build Release Aufgabe3"
} }
] ]
} }

View file

@ -29,7 +29,8 @@ print(calculateAverage(items: items))
// 3.3 // 3.3
func sortListAlphabetical(items: [String]) -> [String] { func sortListAlphabetical(items: [String]) -> [String] {
return items.sorted() let itemsCopy = items
return itemsCopy.sorted()
} }
let stringItems = ["ABC", "CDF", "BDC"] let stringItems = ["ABC", "CDF", "BDC"]
@ -45,7 +46,9 @@ struct ComplexType {
} }
func sortComplexType(items: [ComplexType]) -> [ComplexType] { func sortComplexType(items: [ComplexType]) -> [ComplexType] {
return items.sorted { let itemsCopy = items
return itemsCopy.sorted {
($0.date, $0.priority, $0.title) < ($1.date, $1.priority, $1.title) ($0.date, $0.priority, $0.title) < ($1.date, $1.priority, $1.title)
} }
} }

View file

@ -4,9 +4,9 @@
| ------- | -------------------- | ------------------------------------------------ | ----------------------------------- | ---------------- | | ------- | -------------------- | ------------------------------------------------ | ----------------------------------- | ---------------- |
| 1.1 | Ja | Nein | Nein | impure | | 1.1 | Ja | Nein | Nein | impure |
| 1.2 | Ja | Ja | Ja | pure | | 1.2 | Ja | Ja | Ja | pure |
| 1.3 | Ja | ja | Ja | pure | | 1.3 | Ja | ja | Ja | impure |
| 1.4 | Ja | Nein | Ja | impure | | 1.4 | Ja | Nein | Ja | impure |
| 1.5 | Ja | Ja | Ja | pure | | 1.5 | Ja | Ja | Ja | impure |
| 1.6 | Ja | Ja | Nein | impure | | 1.6 | Ja | Ja | Nein | impure |
## Aufgabe 1.1 ## Aufgabe 1.1
@ -40,7 +40,11 @@ console.log(add(2, 4)); // Ausgabe: 6
```js ```js
function firstCharacter(str) { function firstCharacter(str) {
return str.charAt(0); if (!len(str) > 0) {
return str.charAt(0);
} else {
return "";
}
} }
console.log(firstCharacter("Hello")); // Ausgabe: H console.log(firstCharacter("Hello")); // Ausgabe: H
@ -64,7 +68,11 @@ console.log(multiplyWithRandom(10, Math.random())); // Ausgabe: Eine zufällige
```js ```js
// Funktion zum Teilen einer Zahl durch eine andere // Funktion zum Teilen einer Zahl durch eine andere
function divideNumbers(dividend, divisor) { function divideNumbers(dividend, divisor) {
return dividend / divisor; if (dividen != 0 && divisor != 0) {
return dividend / divisor;
} else {
return 0;
}
} }
console.log(divideNumbers(10, 2)); // Ausgabe: 5 console.log(divideNumbers(10, 2)); // Ausgabe: 5

View file

@ -11,6 +11,16 @@ let package = Package(
.executableTarget( .executableTarget(
name: "m323" name: "m323"
), ),
.executableTarget(
name: "WeDontLikeCharA",
path: "02",
sources: ["WeDontLikeCharA.swift"]
),
.executableTarget(
name: "Aufgabe3",
path: "03",
sources: ["Aufgabe3.swift"]
),
.testTarget( .testTarget(
name: "m323Tests", name: "m323Tests",
dependencies: ["m323"] dependencies: ["m323"]

View file

@ -0,0 +1,6 @@
import Testing
@testable import m323
@Test func example() async throws {
// Write your test here and use APIs like `#expect(...)` to check expected conditions.
}