From 767346f4081b98c7896dea72bcb4d996ef38a666 Mon Sep 17 00:00:00 2001 From: cediackermann Date: Mon, 18 May 2026 08:18:00 +0200 Subject: [PATCH] Correct mistakes --- .vscode/launch.json | 40 +++++++++++++++++++++++++++++++++ 03/Aufgabe3.swift | 7 ++++-- 03/PureOrNotPure.md | 16 +++++++++---- Package.swift | 10 +++++++++ Tests/m323Tests/m323Tests.swift | 6 +++++ 5 files changed, 73 insertions(+), 6 deletions(-) create mode 100644 Tests/m323Tests/m323Tests.swift diff --git a/.vscode/launch.json b/.vscode/launch.json index e4eaac7..8960b4e 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -19,6 +19,46 @@ "target": "m323", "configuration": "release", "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" } ] } diff --git a/03/Aufgabe3.swift b/03/Aufgabe3.swift index 933e2ef..6a5b5bc 100644 --- a/03/Aufgabe3.swift +++ b/03/Aufgabe3.swift @@ -29,7 +29,8 @@ print(calculateAverage(items: items)) // 3.3 func sortListAlphabetical(items: [String]) -> [String] { - return items.sorted() + let itemsCopy = items + return itemsCopy.sorted() } let stringItems = ["ABC", "CDF", "BDC"] @@ -45,7 +46,9 @@ struct 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) } } diff --git a/03/PureOrNotPure.md b/03/PureOrNotPure.md index 8ab812a..61b8ebd 100644 --- a/03/PureOrNotPure.md +++ b/03/PureOrNotPure.md @@ -4,9 +4,9 @@ | ------- | -------------------- | ------------------------------------------------ | ----------------------------------- | ---------------- | | 1.1 | Ja | Nein | Nein | impure | | 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.5 | Ja | Ja | Ja | pure | +| 1.5 | Ja | Ja | Ja | impure | | 1.6 | Ja | Ja | Nein | impure | ## Aufgabe 1.1 @@ -40,7 +40,11 @@ console.log(add(2, 4)); // Ausgabe: 6 ```js function firstCharacter(str) { - return str.charAt(0); + if (!len(str) > 0) { + return str.charAt(0); + } else { + return ""; + } } console.log(firstCharacter("Hello")); // Ausgabe: H @@ -64,7 +68,11 @@ console.log(multiplyWithRandom(10, Math.random())); // Ausgabe: Eine zufällige ```js // Funktion zum Teilen einer Zahl durch eine andere 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 diff --git a/Package.swift b/Package.swift index 140689d..84c75c2 100644 --- a/Package.swift +++ b/Package.swift @@ -11,6 +11,16 @@ let package = Package( .executableTarget( name: "m323" ), + .executableTarget( + name: "WeDontLikeCharA", + path: "02", + sources: ["WeDontLikeCharA.swift"] + ), + .executableTarget( + name: "Aufgabe3", + path: "03", + sources: ["Aufgabe3.swift"] + ), .testTarget( name: "m323Tests", dependencies: ["m323"] diff --git a/Tests/m323Tests/m323Tests.swift b/Tests/m323Tests/m323Tests.swift new file mode 100644 index 0000000..b503c0d --- /dev/null +++ b/Tests/m323Tests/m323Tests.swift @@ -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. +}