mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-03-20 04:01:32 -04:00
feat(curriculum): add wherefore art thou challenge lab (#62173)
This commit is contained in:
@@ -3528,6 +3528,12 @@
|
||||
"In this lab, you will practice using higher order functions to find the symmetric difference between two arrays."
|
||||
]
|
||||
},
|
||||
"lab-matching-object-filter": {
|
||||
"title": "Implement a Matching Object Filter",
|
||||
"intro": [
|
||||
"In this lab, you will create a function that looks through an array of objects and returns an array of all objects that have matching property and value pairs."
|
||||
]
|
||||
},
|
||||
"lab-sum-all-primes-calculator": {
|
||||
"title": "Build a Prime Number Sum Calculator",
|
||||
"intro": [
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
---
|
||||
title: Introduction to the Implement a Matching Object Filter
|
||||
block: lab-matching-object-filter
|
||||
superBlock: full-stack-developer
|
||||
---
|
||||
|
||||
## Introduction to the Implement a Matching Object Filter
|
||||
|
||||
In this lab, you will create a function that filters an array of objects and returns only those objects that match all the key-value pairs specified in a source object.
|
||||
@@ -0,0 +1,135 @@
|
||||
---
|
||||
id: a8e512fbe388ac2f9198f0fa
|
||||
title: Implement a Matching Object Filter
|
||||
challengeType: 26
|
||||
dashedName: implement-a-matching-object-filter
|
||||
---
|
||||
|
||||
# --description--
|
||||
|
||||
In this lab, you will create a function that filters an array of objects and returns only those objects that match all key-value pairs in a given source object.
|
||||
|
||||
**Objective**: Fulfill the user stories below and get all the tests to pass to complete the lab.
|
||||
|
||||
**User Stories:**
|
||||
|
||||
1. You should have a `whatIsInAName` function that accepts two arguments, an array of objects and a source object.
|
||||
1. The `whatIsInAName` function should return a new array containing only the objects from the collection that have all the key–value pairs present in the source object.
|
||||
1. If no objects match all the key–value pairs from the source, the function should return an empty array. For example:
|
||||
|
||||
```js
|
||||
whatIsInAName(
|
||||
[
|
||||
{ first: "Romeo", last: "Montague" },
|
||||
{ first: "Mercutio", last: null },
|
||||
{ first: "Tybalt", last: "Capulet" }
|
||||
],
|
||||
{ last: "Capulet" }
|
||||
);
|
||||
// should return [{ first: "Tybalt", last: "Capulet" }]
|
||||
```
|
||||
|
||||
# --hints--
|
||||
|
||||
You should have a `whatIsInAName` function.
|
||||
|
||||
```js
|
||||
assert.isFunction(whatIsInAName);
|
||||
```
|
||||
|
||||
`whatIsInAName([{ first: "Romeo", last: "Montague" }, { first: "Mercutio", last: null }, { first: "Tybalt", last: "Capulet" }], { last: "Capulet" })` should return `[{ first: "Tybalt", last: "Capulet" }]`.
|
||||
|
||||
```js
|
||||
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 })` should return `[{"apple": 1}, {"apple": 1}, {"apple": 1, "bat": 2}]`.
|
||||
|
||||
```js
|
||||
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 })` should return `[{"apple": 1, "bat": 2}, {"apple": 1, "bat": 2, "cookie": 2}]`.
|
||||
|
||||
```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 }]
|
||||
);
|
||||
```
|
||||
|
||||
`whatIsInAName([{ "apple": 1, "bat": 2 }, { "apple": 1 }, { "apple": 1, "bat": 2, "cookie": 2 }], { "apple": 1, "cookie": 2 })` should return `[{"apple": 1, "bat": 2, "cookie": 2}]`.
|
||||
|
||||
```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 }]
|
||||
);
|
||||
```
|
||||
|
||||
`whatIsInAName([{ "apple": 1, "bat": 2 }, { "apple": 1 }, { "apple": 1, "bat": 2, "cookie": 2 }, { "bat": 2 }], { "apple": 1, "bat": 2 })` should return `[{"apple": 1, "bat": 2}, {"apple": 1, "bat": 2, "cookie": 2}]`
|
||||
|
||||
```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 }]
|
||||
);
|
||||
```
|
||||
|
||||
`whatIsInAName([{"a": 1, "b": 2, "c": 3}], {"a": 1, "b": 9999, "c": 3})` should return `[]`.
|
||||
|
||||
```js
|
||||
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})` should return `[]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(
|
||||
whatIsInAName([{ "a": 1, "b": 2, "c": 3, "d": 9999 }], { "a": 1, "b": 9999, "c": 3 }),
|
||||
[]
|
||||
);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
function whatIsInAName(collection, source) {
|
||||
const sourceKeys = Object.keys(source);
|
||||
|
||||
return collection.filter(obj =>
|
||||
sourceKeys.every(key => obj.hasOwnProperty(key) && obj[key] === source[key])
|
||||
);
|
||||
}
|
||||
```
|
||||
15
curriculum/structure/blocks/lab-matching-object-filter.json
Normal file
15
curriculum/structure/blocks/lab-matching-object-filter.json
Normal file
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"name": "Implement a Matching Object Filter",
|
||||
"isUpcomingChange": false,
|
||||
"dashedName": "lab-matching-object-filter",
|
||||
"helpCategory": "JavaScript",
|
||||
"blockLayout": "link",
|
||||
"blockType": "lab",
|
||||
"usesMultifileEditor": true,
|
||||
"challengeOrder": [
|
||||
{
|
||||
"id": "a8e512fbe388ac2f9198f0fa",
|
||||
"title": "Implement a Matching Object Filter"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -402,6 +402,7 @@
|
||||
"lab-book-organizer",
|
||||
"lab-sorted-index-finder",
|
||||
"lab-symmetric-difference",
|
||||
"lab-matching-object-filter",
|
||||
"lab-sum-all-primes-calculator",
|
||||
"lab-deep-flattening-tool",
|
||||
"review-javascript-higher-order-functions",
|
||||
@@ -718,7 +719,6 @@
|
||||
"comingSoon": true,
|
||||
"blocks": [
|
||||
"lecture-working-with-common-data-structures",
|
||||
|
||||
"lab-hash-table",
|
||||
"review-data-structures",
|
||||
"quiz-data-structures"
|
||||
@@ -879,26 +879,14 @@
|
||||
"comingSoon": true,
|
||||
"blocks": []
|
||||
},
|
||||
{
|
||||
"dashedName": "websockets",
|
||||
"comingSoon": true,
|
||||
"blocks": []
|
||||
},
|
||||
{
|
||||
"dashedName": "node-and-sql",
|
||||
"comingSoon": true,
|
||||
"blocks": []
|
||||
},
|
||||
{ "dashedName": "websockets", "comingSoon": true, "blocks": [] },
|
||||
{ "dashedName": "node-and-sql", "comingSoon": true, "blocks": [] },
|
||||
{
|
||||
"dashedName": "security-and-privacy",
|
||||
"comingSoon": true,
|
||||
"blocks": []
|
||||
},
|
||||
{
|
||||
"dashedName": "authentication",
|
||||
"comingSoon": true,
|
||||
"blocks": []
|
||||
},
|
||||
{ "dashedName": "authentication", "comingSoon": true, "blocks": [] },
|
||||
{
|
||||
"dashedName": "tooling-and-deployment",
|
||||
"comingSoon": true,
|
||||
@@ -915,11 +903,7 @@
|
||||
"comingSoon": true,
|
||||
"blocks": []
|
||||
},
|
||||
{
|
||||
"dashedName": "capstone-project",
|
||||
"comingSoon": true,
|
||||
"blocks": []
|
||||
},
|
||||
{ "dashedName": "capstone-project", "comingSoon": true, "blocks": [] },
|
||||
{
|
||||
"dashedName": "certified-full-stack-developer-exam",
|
||||
"comingSoon": true,
|
||||
|
||||
Reference in New Issue
Block a user