From ad098e2fba2535aa8efec0341df928ca9251a753 Mon Sep 17 00:00:00 2001 From: Hillary Nyakundi <63947040+larymak@users.noreply.github.com> Date: Mon, 22 Sep 2025 08:39:59 +0300 Subject: [PATCH] feat(curriculum): add wherefore art thou challenge lab (#62173) --- client/i18n/locales/english/intro.json | 6 + .../lab-matching-object-filter/index.md | 9 ++ .../a8e512fbe388ac2f9198f0fa.md | 135 ++++++++++++++++++ .../blocks/lab-matching-object-filter.json | 15 ++ .../superblocks/full-stack-developer.json | 26 +--- 5 files changed, 170 insertions(+), 21 deletions(-) create mode 100644 client/src/pages/learn/full-stack-developer/lab-matching-object-filter/index.md create mode 100644 curriculum/challenges/english/blocks/lab-matching-object-filter/a8e512fbe388ac2f9198f0fa.md create mode 100644 curriculum/structure/blocks/lab-matching-object-filter.json diff --git a/client/i18n/locales/english/intro.json b/client/i18n/locales/english/intro.json index 050c506c6cf..202dddd76b3 100644 --- a/client/i18n/locales/english/intro.json +++ b/client/i18n/locales/english/intro.json @@ -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": [ diff --git a/client/src/pages/learn/full-stack-developer/lab-matching-object-filter/index.md b/client/src/pages/learn/full-stack-developer/lab-matching-object-filter/index.md new file mode 100644 index 00000000000..1780acb93e4 --- /dev/null +++ b/client/src/pages/learn/full-stack-developer/lab-matching-object-filter/index.md @@ -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. diff --git a/curriculum/challenges/english/blocks/lab-matching-object-filter/a8e512fbe388ac2f9198f0fa.md b/curriculum/challenges/english/blocks/lab-matching-object-filter/a8e512fbe388ac2f9198f0fa.md new file mode 100644 index 00000000000..577bc0eb5aa --- /dev/null +++ b/curriculum/challenges/english/blocks/lab-matching-object-filter/a8e512fbe388ac2f9198f0fa.md @@ -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]) + ); +} +``` diff --git a/curriculum/structure/blocks/lab-matching-object-filter.json b/curriculum/structure/blocks/lab-matching-object-filter.json new file mode 100644 index 00000000000..9d7ecc1270b --- /dev/null +++ b/curriculum/structure/blocks/lab-matching-object-filter.json @@ -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" + } + ] +} diff --git a/curriculum/structure/superblocks/full-stack-developer.json b/curriculum/structure/superblocks/full-stack-developer.json index e1c61336538..a20100509a5 100644 --- a/curriculum/structure/superblocks/full-stack-developer.json +++ b/curriculum/structure/superblocks/full-stack-developer.json @@ -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,