2021-02-06 04:42:36 +00:00
---
id: a8e512fbe388ac2f9198f0fa
2021-03-23 08:41:00 -06:00
title: Donde estás
2021-02-06 04:42:36 +00:00
challengeType: 5
forumTopicId: 16092
dashedName: wherefore-art-thou
---
# --description--
2021-03-23 08:41:00 -06:00
Crea una función que busque a través de un arreglo de objetos (primer argumento) y devuelva un arreglo de todos los objetos que tengan pares de nombre y valor coincidentes (segundo argumento). Cada par de nombre y valor del objeto fuente tiene que estar presente en el objeto de la colección si se va a incluir en el arreglo devuelto.
2021-02-06 04:42:36 +00:00
2021-03-23 08:41:00 -06:00
Por ejemplo, si el primer argumento es `[{ first: "Romeo", last: "Montague" }, { first: "Mercutio", last: null }, { first: "Tybalt", last: "Capulet" }]` , y el segundo argumento es `{ last: "Capulet" }` , entonces debes devolver el tercer objeto del arreglo (el primer argumento), porque contiene el nombre y su valor, el cual fue pasado como segundo argumento.
2021-02-06 04:42:36 +00:00
# --hints--
2021-03-23 08:41:00 -06:00
`whatIsInAName([{ first: "Romeo", last: "Montague" }, { first: "Mercutio", last: null }, { first: "Tybalt", last: "Capulet" }], { last: "Capulet" })` debe devolver `[{ first: "Tybalt", last: "Capulet" }]` .
2021-02-06 04:42:36 +00:00
```js
assert.deepEqual(
whatIsInAName(
[
{ first: 'Romeo', last: 'Montague' },
{ first: 'Mercutio', last: null },
{ first: 'Tybalt', last: 'Capulet' }
],
{ last: 'Capulet' }
),
[{ first: 'Tybalt', last: 'Capulet' }]
);
```
2021-03-23 08:41:00 -06:00
`whatIsInAName([{ "apple": 1 }, { "apple": 1 }, { "apple": 1, "bat": 2 }], { "apple": 1 })` debe devolver `[{ "apple": 1 }, { "apple": 1 }, { "apple": 1, "bat": 2 }]` .
2021-02-06 04:42:36 +00:00
```js
assert.deepEqual(
whatIsInAName([{ apple: 1 }, { apple: 1 }, { apple: 1, bat: 2 }], {
apple: 1
}),
[{ apple: 1 }, { apple: 1 }, { apple: 1, bat: 2 }]
);
```
2021-03-23 08:41:00 -06:00
`whatIsInAName([{ "apple": 1, "bat": 2 }, { "bat": 2 }, { "apple": 1, "bat": 2, "cookie": 2 }], { "apple": 1, "bat": 2 })` debe devolver `[{ "apple": 1, "bat": 2 }, { "apple": 1, "bat": 2, "cookie": 2 }]` .
2021-02-06 04:42:36 +00:00
```js
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 }
]
);
```
2021-03-23 08:41:00 -06:00
`whatIsInAName([{ "apple": 1, "bat": 2 }, { "apple": 1 }, { "apple": 1, "bat": 2, "cookie": 2 }], { "apple": 1, "cookie": 2 })` debe devolver `[{ "apple": 1, "bat": 2, "cookie": 2 }]` .
2021-02-06 04:42:36 +00:00
```js
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 }]
);
```
2021-03-23 08:41:00 -06:00
`whatIsInAName([{ "apple": 1, "bat": 2 }, { "apple": 1 }, { "apple": 1, "bat": 2, "cookie": 2 }, { "bat":2 }], { "apple": 1, "bat": 2 })` debe devolver `[{ "apple": 1, "bat": 2 }, { "apple": 1, "bat": 2, "cookie":2 }]` .
2021-02-06 04:42:36 +00:00
```js
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 }
]
);
```
2021-03-23 08:41:00 -06:00
`whatIsInAName([{"a": 1, "b": 2, "c": 3}], {"a": 1, "b": 9999, "c": 3})` debe devolver `[]`
2021-02-06 04:42:36 +00:00
```js
assert.deepEqual(
whatIsInAName([{ a: 1, b: 2, c: 3 }], { a: 1, b: 9999, c: 3 }),
[]
);
```
# --seed--
## --seed-contents--
```js
function whatIsInAName(collection, source) {
2021-10-27 15:10:57 +00:00
const arr = [];
2021-02-06 04:42:36 +00:00
// Only change code below this line
// Only change code above this line
return arr;
}
whatIsInAName([{ first: "Romeo", last: "Montague" }, { first: "Mercutio", last: null }, { first: "Tybalt", last: "Capulet" }], { last: "Capulet" });
```
# --solutions--
```js
function whatIsInAName(collection, source) {
2021-10-27 15:10:57 +00:00
const arr = [];
const keys = Object.keys(source);
2021-02-06 04:42:36 +00:00
collection.forEach(function(e) {
if(keys.every(function(key) {return e[key] === source[key];})) {
arr.push(e);
}
});
return arr;
}
```