3.9 KiB
id, title, challengeType, forumTopicId, dashedName
| id | title | challengeType | forumTopicId | dashedName |
|---|---|---|---|---|
| a8e512fbe388ac2f9198f0fa | Deshalb bist du | 1 | 16092 | wherefore-art-thou |
--description--
Erstelle eine Funktion, die ein Array mit Objekten (erstes Argument) durchsucht und ein Array mit allen Objekten zurückgibt, die übereinstimmende Namens- und Wertepaare haben (zweites Argument). Jedes Namens- und Wertepaar des Quellobjekts muss im Objekt aus der Sammlung vorhanden sein, wenn es in das zurückgegebene Array aufgenommen werden soll.
Wenn das erste Argument zum Beispiel [{ first: "Romeo", last: "Montague" }, { first: "Mercutio", last: null }, { first: "Tybalt", last: "Capulet" }], und das zweite Argument ist { last: "Capulet" }, dann musst du das dritte Objekt aus dem Array (das erste Argument) zurückgeben, denn es enthält den Namen und seinen Wert, der als zweites Argument übergeben wurde.
--hints--
whatIsInAName([{ first: "Romeo", last: "Montague" }, { first: "Mercutio", last: null }, { first: "Tybalt", last: "Capulet" }], { last: "Capulet" }) sollte [{ first: "Tybalt", last: "Capulet" }] zurückgeben.
assert.deepEqual(
whatIsInAName(
[
{ first: 'Romeo', last: 'Montague' },
{ first: 'Mercutio', last: null },
{ first: 'Tybalt', last: 'Capulet' }
],
{ last: 'Capulet' }
),
[{ first: 'Tybalt', last: 'Capulet' }]
);
whatIsInAName([{ "apple": 1 }, { "apple": 1 }, { "apple": 1, "bat": 2 }], { "apple": 1 }) sollte[{ "apple": 1 }, { "apple": 1 }, { "apple": 1, "bat": 2 }] zurückgeben.
assert.deepEqual(
whatIsInAName([{ apple: 1 }, { apple: 1 }, { apple: 1, bat: 2 }], {
apple: 1
}),
[{ apple: 1 }, { apple: 1 }, { apple: 1, bat: 2 }]
);
whatIsInAName([{ "apple": 1, "bat": 2 }, { "bat": 2 }, { "apple": 1, "bat": 2, "cookie": 2 }], { "apple": 1, "bat": 2 }) sollte[{ "apple": 1, "bat": 2 }, { "apple": 1, "bat": 2, "cookie": 2 }] zurückgeben.
assert.deepEqual(
whatIsInAName(
[{ apple: 1, bat: 2 }, { bat: 2 }, { apple: 1, bat: 2, cookie: 2 }],
{ apple: 1, bat: 2 }
),
[
{ apple: 1, bat: 2 },
{ apple: 1, bat: 2, cookie: 2 }
]
);
whatIsInAName([{ "apple": 1, "bat": 2 }, { "apple": 1 }, { "apple": 1, "bat": 2, "cookie": 2 }], { "apple": 1, "cookie": 2 }) sollte [{ "apple": 1, "bat": 2, "cookie": 2 }] zurückgeben.
assert.deepEqual(
whatIsInAName(
[{ apple: 1, bat: 2 }, { apple: 1 }, { apple: 1, bat: 2, cookie: 2 }],
{ apple: 1, cookie: 2 }
),
[{ apple: 1, bat: 2, cookie: 2 }]
);
whatIsInAName([{ "apple": 1, "bat": 2 }, { "apple": 1 }, { "apple": 1, "bat": 2, "cookie": 2 }, { "bat":2 }], { "apple": 1, "bat": 2 }) sollte[{ "apple": 1, "bat": 2 }, { "apple": 1, "bat": 2, "cookie":2 }] zurückgeben.
assert.deepEqual(
whatIsInAName(
[
{ apple: 1, bat: 2 },
{ apple: 1 },
{ apple: 1, bat: 2, cookie: 2 },
{ bat: 2 }
],
{ apple: 1, bat: 2 }
),
[
{ apple: 1, bat: 2 },
{ apple: 1, bat: 2, cookie: 2 }
]
);
whatIsInAName([{"a": 1, "b": 2, "c": 3}], {"a": 1, "b": 9999, "c": 3}) sollte [] zurückgeben.
assert.deepEqual(
whatIsInAName([{ a: 1, b: 2, c: 3 }], { a: 1, b: 9999, c: 3 }),
[]
);
whatIsInAName([{"a": 1, "b": 2, "c": 3, "d": 9999}], {"a": 1, "b": 9999, "c": 3}) sollte [] zurückgeben.
assert.deepEqual(
whatIsInAName([{ a: 1, b: 2, c: 3, d: 9999 }], { a: 1, b: 9999, c: 3 }),
[]
);
--seed--
--seed-contents--
function whatIsInAName(collection, source) {
}
whatIsInAName([{ first: "Romeo", last: "Montague" }, { first: "Mercutio", last: null }, { first: "Tybalt", last: "Capulet" }], { last: "Capulet" });
--solutions--
function whatIsInAName(collection, source) {
const arr = [];
const keys = Object.keys(source);
collection.forEach(function(e) {
if(keys.every(function(key) {return e[key] === source[key];})) {
arr.push(e);
}
});
return arr;
}