Skip to content

Strings #194

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions 1-js/05-data-types/03-string/1-ucfirst/solution.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
We can't "replace" the first character, because strings in JavaScript are immutable.
Wir können das erste Zeichen nicht "ersetzen", da Strings in JavaScript unveränderlich sind.

But we can make a new string based on the existing one, with the uppercased first character:
Wir können jedoch einen neuen String basierend auf dem bestehenden erstellen, mit einem großgeschriebenen ersten Buchstaben:

```js
let newStr = str[0].toUpperCase() + str.slice(1);
```

There's a small problem though. If `str` is empty, then `str[0]` is `undefined`, and as `undefined` doesn't have the `toUpperCase()` method, we'll get an error.
Es gibt jedoch ein kleines Problem. Wenn `str` leer ist, dann ist `str[0]` `undefined`, und da `undefined` nicht die Methode `toUpperCase()` besitzt, erhalten wir einen Fehler.

The easiest way out is to add a test for an empty string, like this:
Der einfachste Ausweg ist, eine Überprüfung auf einen leeren String hinzuzufügen, so wie hier:

```js run demo
function ucFirst(str) {
Expand Down
5 changes: 2 additions & 3 deletions 1-js/05-data-types/03-string/1-ucfirst/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ importance: 5

---

# Uppercase the first character
# Den ersten Buchstaben großschreiben

Write a function `ucFirst(str)` that returns the string `str` with the uppercased first character, for instance:
Schreibe eine Funktion `ucFirst(str)`, die den String `str` zurückgibt, wobei der erste Buchstabe großgeschrieben ist, beispielsweise:

```js
ucFirst("john") == "John";
```

3 changes: 1 addition & 2 deletions 1-js/05-data-types/03-string/2-check-spam/solution.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
To make the search case-insensitive, let's bring the string to lower case and then search:
Um die Suche unabhängig von Groß- und Kleinschreibung zu gestalten, bringen wir den String in Kleinbuchstaben und suchen dann:

```js run demo
function checkSpam(str) {
Expand All @@ -11,4 +11,3 @@ alert( checkSpam('buy ViAgRA now') );
alert( checkSpam('free xxxxx') );
alert( checkSpam("innocent rabbit") );
```

7 changes: 3 additions & 4 deletions 1-js/05-data-types/03-string/2-check-spam/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ importance: 5

---

# Check for spam
# Überprüfung auf Spam

Write a function `checkSpam(str)` that returns `true` if `str` contains 'viagra' or 'XXX', otherwise `false`.
Schreibe eine Funktion `checkSpam(str)`, die `true` zurückgibt, wenn `str` 'viagra' oder 'XXX' enthält, ansonsten `false`.

The function must be case-insensitive:
Die Funktion muss Groß- und Kleinschreibung ignorieren:

```js
checkSpam('buy ViAgRA now') == true
checkSpam('free xxxxx') == true
checkSpam("innocent rabbit") == false
```

4 changes: 2 additions & 2 deletions 1-js/05-data-types/03-string/3-truncate/solution.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The maximal length must be `maxlength`, so we need to cut it a little shorter, to give space for the ellipsis.
Die maximale Länge muss `maxlength` sein, daher müssen wir den Text ein wenig kürzen, um Platz für die Auslassungspunkte zu schaffen.

Note that there is actually a single Unicode character for an ellipsis. That's not three dots.
Beachte, dass es tatsächlich ein einzelnes Unicode-Zeichen für eine Auslassung gibt. Das sind nicht drei Punkte.

```js run demo
function truncate(str, maxlength) {
Expand Down
8 changes: 4 additions & 4 deletions 1-js/05-data-types/03-string/3-truncate/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ importance: 5

---

# Truncate the text
# Kürze den Text

Create a function `truncate(str, maxlength)` that checks the length of the `str` and, if it exceeds `maxlength` -- replaces the end of `str` with the ellipsis character `"…"`, to make its length equal to `maxlength`.
Erstelle eine Funktion `truncate(str, maxlength)`, die die Länge des Strings `str` überprüft und - falls diese `maxlength` übersteigt - das Ende von `str` mit dem Auslassungszeichen `"…"` ersetzt, um seine Länge an `maxlength` anzupassen.

The result of the function should be the truncated (if needed) string.
Das Ergebnis der Funktion sollte der gekürzte (falls nötig) String sein.

For instance:
Zum Beispiel:

```js
truncate("What I'd like to tell on this topic is:", 20) = "What I'd like to te…"
Expand Down
9 changes: 4 additions & 5 deletions 1-js/05-data-types/03-string/4-extract-currency/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ importance: 4

---

# Extract the money
# Extrahiere den Geldbetrag

We have a cost in the form `"$120"`. That is: the dollar sign goes first, and then the number.
Wir haben Kosten in der Form `"$120"`. Das heißt: das Dollarzeichen steht zuerst, und dann die Zahl.

Create a function `extractCurrencyValue(str)` that would extract the numeric value from such string and return it.
Erstelle eine Funktion `extractCurrencyValue(str)`, die den numerischen Wert aus einem solchen String extrahiert und ihn zurückgibt.

The example:
Das Beispiel:

```js
alert( extractCurrencyValue('$120') === 120 ); // true
```

Loading