Skip to content
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
6 changes: 3 additions & 3 deletions 1-js/05-data-types/03-string/1-ucfirst/_js.view/test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
describe("ucFirst", function() {
it('Uppercases the first symbol', function() {
describe("ucFirst", function () {
it('Stort begyndelsesbogstav', function () {
assert.strictEqual(ucFirst("john"), "John");
});

it("Doesn't die on an empty string", function() {
it("Fejler ikke ved en tom streng", function () {
assert.strictEqual(ucFirst(""), "");
});
});
10 changes: 5 additions & 5 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.
Vi kan ikke "erstatte" det første tegn, fordi strenge i JavaScript er uforanderlige (immutable).

But we can make a new string based on the existing one, with the uppercased first character:
Men vi kan lave en ny streng baseret på den eksisterende, med det første tegn i stort:

```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.
Der er dog et lille problem. Hvis `str` er tom, så er `str[0]` `undefined`, og da `undefined` ikke har metoden `toUpperCase()`, får vi en fejl.

The easiest way out is to add a test for an empty string, like this:
Den nemmeste løsning er at tilføje en test for en tom streng, sådan her:

```js run demo
function ucFirst(str) {
Expand All @@ -17,5 +17,5 @@ function ucFirst(str) {
return str[0].toUpperCase() + str.slice(1);
}

alert( ucFirst("john") ); // John
alert( ucFirst("karsten") ); // Karsten
```
4 changes: 2 additions & 2 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,9 +2,9 @@ importance: 5

---

# Uppercase the first character
# Stort begyndelsesbogstav

Write a function `ucFirst(str)` that returns the string `str` with the uppercased first character, for instance:
Skriv en funktion `ucFirst(str)`, der returnerer strengen `str` med stort begyndelsesbogstav, for eksempel:

```js
ucFirst("john") == "John";
Expand Down
8 changes: 4 additions & 4 deletions 1-js/05-data-types/03-string/2-check-spam/_js.view/test.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
describe("checkSpam", function() {
it('finds spam in "buy ViAgRA now"', function() {
describe("checkSpam", function () {
it('finder spam i "buy ViAgRA now"', function () {
assert.isTrue(checkSpam('buy ViAgRA now'));
});

it('finds spam in "free xxxxx"', function() {
it('finder spam i "free xxxxx"', function () {
assert.isTrue(checkSpam('free xxxxx'));
});

it('no spam in "innocent rabbit"', function() {
it('ingen spam i "innocent rabbit"', function () {
assert.isFalse(checkSpam('innocent rabbit'));
});
});
2 changes: 1 addition & 1 deletion 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:
For at gøre søgningen case-insensitive, lad os bringe strengen til små bogstaver og derefter søge:

```js run demo
function checkSpam(str) {
Expand Down
6 changes: 3 additions & 3 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,11 +2,11 @@ importance: 5

---

# Check for spam
# Tjek for spam

Write a function `checkSpam(str)` that returns `true` if `str` contains 'viagra' or 'XXX', otherwise `false`.
Skriv en funktion `checkSpam(str)`, der returnerer `true`, hvis `str` indeholder 'viagra' eller 'XXX', ellers `false`.

The function must be case-insensitive:
Funktionen skal være case-insensitive:

```js
checkSpam('buy ViAgRA now') == true
Expand Down
14 changes: 7 additions & 7 deletions 1-js/05-data-types/03-string/3-truncate/_js.view/test.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
describe("truncate", function() {
it("truncate the long string to the given length (including the ellipsis)", function() {
describe("truncate", function () {
it("Afkort den lange streng til den givne længde (inklusive ellipsen)", function () {
assert.equal(
truncate("What I'd like to tell on this topic is:", 20),
"What I'd like to te…"
truncate("Det jeg vil fortælle om emnet er følgende:", 20),
"Det jeg vil fortæll…"
);
});

it("doesn't change short strings", function() {
it("Ændrer ikke korte strenge", function () {
assert.equal(
truncate("Hi everyone!", 20),
"Hi everyone!"
truncate("Hej alle sammen!", 20),
"Hej alle sammen!"
);
});

Expand Down
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.
Den maksimale længde skal være `maxlength`, så vi er nødt til at skære den lidt kortere for at give plads til ellipsen (…).

Note that there is actually a single Unicode character for an ellipsis. That's not three dots.
Bemærk, at der faktisk er et enkelt Unicode-tegn for en ellipsis. Det er ikke tre prikker.

```js run demo
function truncate(str, maxlength) {
Expand Down
12 changes: 6 additions & 6 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,16 +2,16 @@ importance: 5

---

# Truncate the text
# Afkort teksten

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`.
Opret en funktion `truncate(str, maxlength)`, der tjekker længden af `str` og, hvis den overskrider `maxlength` -- erstatter slutningen af `str` med ellipsis-tegnet `"…"`, så dens længde bliver lig med `maxlength`.

The result of the function should be the truncated (if needed) string.
Resultatet af funktionen skal være den afkortede (hvis nødvendigt) streng.

For instance:
For eksempel:

```js
truncate("What I'd like to tell on this topic is:", 20) == "What I'd like to te…"
truncate("Det jeg vil fortælle om emnet er følgende:", 20) == "Det jeg vil fortæll…"

truncate("Hi everyone!", 20) == "Hi everyone!"
truncate("Hej alle sammen!", 20) == "Hej alle sammen!"
```
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
describe("extractCurrencyValue", function() {
describe("extractCurrencyValue", function () {

it("for the string $120 returns the number 120", function() {
it("for strengen $120 returneres tallet 120", function () {
assert.strictEqual(extractCurrencyValue('$120'), 120);
});

Expand Down
6 changes: 3 additions & 3 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,11 +2,11 @@ importance: 4

---

# Extract the money
# Udtræk beløbet

We have a cost in the form `"$120"`. That is: the dollar sign goes first, and then the number.
Vi har en pris i formen `"$120"`. Det vil sige: dollartegnet kommer først, og derefter tallet.

Create a function `extractCurrencyValue(str)` that would extract the numeric value from such string and return it.
Opret en funktion `extractCurrencyValue(str)`, der udtrækker den numeriske værdi fra sådan en streng og returnerer den.

The example:

Expand Down
Loading