diff --git a/client/i18n/locales/english/intro.json b/client/i18n/locales/english/intro.json index f84b1e8a1e2..d1558edc8fb 100644 --- a/client/i18n/locales/english/intro.json +++ b/client/i18n/locales/english/intro.json @@ -3406,6 +3406,12 @@ "In these lectures, you will learn about the var keyword and why it is not recommended for use anymore. You will also learn about hoisting in JavaScript so you can avoid subtle bugs in your code." ] }, + "lab-falsy-remover": { + "title": "Implement a Falsy Remover", + "intro": [ + "In this lab, you will create a function that removes all falsy values from an array." + ] + }, "lab-inventory-management-program": { "title": "Build an Inventory Management Program", "intro": [ diff --git a/client/src/pages/learn/full-stack-developer/lab-falsy-remover/index.md b/client/src/pages/learn/full-stack-developer/lab-falsy-remover/index.md new file mode 100644 index 00000000000..323b8f39005 --- /dev/null +++ b/client/src/pages/learn/full-stack-developer/lab-falsy-remover/index.md @@ -0,0 +1,9 @@ +--- +title: Introduction to Implement a Falsy Remover +block: lab-falsy-remover +superBlock: full-stack-developer +--- + +## Introduction to Implement a Falsy Remover + +In this lab, you will create a function that removes all falsy values from an array. diff --git a/curriculum/challenges/english/blocks/lab-falsy-remover/adf08ec01beb4f99fc7a68f2.md b/curriculum/challenges/english/blocks/lab-falsy-remover/adf08ec01beb4f99fc7a68f2.md new file mode 100644 index 00000000000..8dbf42daf6f --- /dev/null +++ b/curriculum/challenges/english/blocks/lab-falsy-remover/adf08ec01beb4f99fc7a68f2.md @@ -0,0 +1,84 @@ +--- +id: adf08ec01beb4f99fc7a68f2 +title: Implement a Falsy Remover +challengeType: 26 +dashedName: implement-a-falsy-remover +--- + +# --description-- + +In this lab you will create a function that removes all falsy values from an array. + +Falsy values in JavaScript are `false`, `null`, `0`, `""`, `undefined`, and `NaN`. + +**Objective**: Fulfill the user stories below and get all the tests to pass to complete the lab. + +**User Stories:** + +1. You should have a `bouncer` function that takes an array as argument. +1. The `bouncer` function should return a new array that contains the same elements as the array passed in as argument with the falsy elements removed. +1. The `bouncer` function should not change the array passed in as an argument. + +Hint: Try converting each value to a Boolean. + +# --hints-- + +You should have a `bouncer` function. + +```js +assert.isFunction(bouncer); +``` + +`bouncer([7, "ate", "", false, 9])` should return `[7, "ate", 9]`. + +```js +assert.deepEqual(bouncer([7, 'ate', '', false, 9]), [7, 'ate', 9]); +``` + +`bouncer(["a", "b", "c"])` should return `["a", "b", "c"]`. + +```js +assert.deepEqual(bouncer(['a', 'b', 'c']), ['a', 'b', 'c']); +``` + +`bouncer([false, null, 0, NaN, undefined, ""])` should return `[]`. + +```js +assert.deepEqual(bouncer([false, null, 0, NaN, undefined, '']), []); +``` + +`bouncer([null, NaN, 1, 2, undefined])` should return `[1, 2]`. + +```js +assert.deepEqual(bouncer([null, NaN, 1, 2, undefined]), [1, 2]); +``` + +The `bouncer` function should not mutate the array passed in as argument. + +```js +const arr = ['a', false, 0, 'Naomi']; +bouncer(arr); +assert.deepEqual(arr, ['a', false, 0, 'Naomi']); +``` + +`bouncer([])` should return `[]`. + +```js +assert.deepEqual(bouncer([]), []); +``` + +# --seed-- + +## --seed-contents-- + +```js + +``` + +# --solutions-- + +```js +function bouncer(arr) { + return arr.filter(e => e); +} +``` diff --git a/curriculum/structure/blocks/lab-falsy-remover.json b/curriculum/structure/blocks/lab-falsy-remover.json new file mode 100644 index 00000000000..a498ab2a94d --- /dev/null +++ b/curriculum/structure/blocks/lab-falsy-remover.json @@ -0,0 +1,12 @@ +{ + "name": "Implement a Falsy Remover", + "isUpcomingChange": false, + "dashedName": "lab-falsy-remover", + "helpCategory": "JavaScript", + "challengeOrder": [ + { "id": "adf08ec01beb4f99fc7a68f2", "title": "Implement a Falsy Remover" } + ], + "usesMultifileEditor": true, + "blockType": "lab", + "blockLayout": "link" +} diff --git a/curriculum/structure/superblocks/full-stack-developer.json b/curriculum/structure/superblocks/full-stack-developer.json index 0abe2db2b6d..9d4072d0771 100644 --- a/curriculum/structure/superblocks/full-stack-developer.json +++ b/curriculum/structure/superblocks/full-stack-developer.json @@ -377,6 +377,7 @@ "lab-pyramid-generator", "lab-gradebook-app", "lecture-the-var-keyword-and-hoisting", + "lab-falsy-remover", "lab-inventory-management-program", "lecture-understanding-modules-imports-and-exports", "lab-password-generator",