Object.keys, values, entries by ockley · Pull Request #241 · javascript-tutorial/da.javascript.info · GitHub
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
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ let salaries = {

alert( sumSalaries(salaries) ); // 650
```
Or, optionally, we could also get the sum using `Object.values` and `reduce`:
Eller, alternativt, kan vi også få summen ved hjælp af `Object.values` og `reduce`:

```js
// reduce loops over array of salaries,
// adding them up
// and returns the result
// reduce gennemløber arrayet af lønninger,
// lægger dem sammen
// og returnerer resultatet
function sumSalaries(salaries) {
return Object.values(salaries).reduce((a, b) => a + b, 0) // 650
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ importance: 5

---

# Sum the properties
# Summen af egenskaberne

There is a `salaries` object with arbitrary number of salaries.
Der er et `salaries` objekt med et vilkårligt antal lønninger.

Write the function `sumSalaries(salaries)` that returns the sum of all salaries using `Object.values` and the `for..of` loop.
Skriv funktionen `sumSalaries(salaries)`, der returnerer summen af alle lønninger ved hjælp af `Object.values` og `for..of` løkken.

If `salaries` is empty, then the result must be `0`.
Hvis `salaries` er tom, skal resultatet være `0`.

For instance:
For eksempel:

```js
let salaries = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
describe("count", function() {
it("counts the number of properties", function() {
assert.equal( count({a: 1, b: 2}), 2 );
describe("count", function () {
it("tæl antallet af egenskaber", function () {
assert.equal(count({ a: 1, b: 2 }), 2);
});

it("returns 0 for an empty object", function() {
assert.equal( count({}), 0 );
it("returnerer 0 for et tomt objekt", function () {
assert.equal(count({}), 0);
});

it("ignores symbolic properties", function() {
assert.equal( count({ [Symbol('id')]: 1 }), 0 );
it("ignorerer symbolske egenskaber", function () {
assert.equal(count({ [Symbol('id')]: 1 }), 0);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ importance: 5

---

# Count properties
# Tæl egenskaber

Write a function `count(obj)` that returns the number of properties in the object:
Skriv en funktion `count(obj)`, der returnerer antallet af egenskaber i objektet:

```js
let user = {
Expand All @@ -15,7 +15,8 @@ let user = {
alert( count(user) ); // 2
```

Try to make the code as short as possible.
Prøv at gøre koden så kort som muligt.

P.S. Ignorer symbolske egenskaber, tæl kun "almindelige".

P.S. Ignore symbolic properties, count only "regular" ones.

64 changes: 32 additions & 32 deletions 1-js/05-data-types/09-keys-values-entries/article.md