Skip to content

Commit c2ff82e

Browse files
feat: add falsy bouncer to full stack (freeCodeCamp#61688)
1 parent e17584f commit c2ff82e

5 files changed

Lines changed: 112 additions & 0 deletions

File tree

client/i18n/locales/english/intro.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3406,6 +3406,12 @@
34063406
"In these lectures, you will learn about the <code>var</code> 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."
34073407
]
34083408
},
3409+
"lab-falsy-remover": {
3410+
"title": "Implement a Falsy Remover",
3411+
"intro": [
3412+
"In this lab, you will create a function that removes all falsy values from an array."
3413+
]
3414+
},
34093415
"lab-inventory-management-program": {
34103416
"title": "Build an Inventory Management Program",
34113417
"intro": [
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
title: Introduction to Implement a Falsy Remover
3+
block: lab-falsy-remover
4+
superBlock: full-stack-developer
5+
---
6+
7+
## Introduction to Implement a Falsy Remover
8+
9+
In this lab, you will create a function that removes all falsy values from an array.
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
---
2+
id: adf08ec01beb4f99fc7a68f2
3+
title: Implement a Falsy Remover
4+
challengeType: 26
5+
dashedName: implement-a-falsy-remover
6+
---
7+
8+
# --description--
9+
10+
In this lab you will create a function that removes all falsy values from an array.
11+
12+
Falsy values in JavaScript are `false`, `null`, `0`, `""`, `undefined`, and `NaN`.
13+
14+
**Objective**: Fulfill the user stories below and get all the tests to pass to complete the lab.
15+
16+
**User Stories:**
17+
18+
1. You should have a `bouncer` function that takes an array as argument.
19+
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.
20+
1. The `bouncer` function should not change the array passed in as an argument.
21+
22+
Hint: Try converting each value to a Boolean.
23+
24+
# --hints--
25+
26+
You should have a `bouncer` function.
27+
28+
```js
29+
assert.isFunction(bouncer);
30+
```
31+
32+
`bouncer([7, "ate", "", false, 9])` should return `[7, "ate", 9]`.
33+
34+
```js
35+
assert.deepEqual(bouncer([7, 'ate', '', false, 9]), [7, 'ate', 9]);
36+
```
37+
38+
`bouncer(["a", "b", "c"])` should return `["a", "b", "c"]`.
39+
40+
```js
41+
assert.deepEqual(bouncer(['a', 'b', 'c']), ['a', 'b', 'c']);
42+
```
43+
44+
`bouncer([false, null, 0, NaN, undefined, ""])` should return `[]`.
45+
46+
```js
47+
assert.deepEqual(bouncer([false, null, 0, NaN, undefined, '']), []);
48+
```
49+
50+
`bouncer([null, NaN, 1, 2, undefined])` should return `[1, 2]`.
51+
52+
```js
53+
assert.deepEqual(bouncer([null, NaN, 1, 2, undefined]), [1, 2]);
54+
```
55+
56+
The `bouncer` function should not mutate the array passed in as argument.
57+
58+
```js
59+
const arr = ['a', false, 0, 'Naomi'];
60+
bouncer(arr);
61+
assert.deepEqual(arr, ['a', false, 0, 'Naomi']);
62+
```
63+
64+
`bouncer([])` should return `[]`.
65+
66+
```js
67+
assert.deepEqual(bouncer([]), []);
68+
```
69+
70+
# --seed--
71+
72+
## --seed-contents--
73+
74+
```js
75+
76+
```
77+
78+
# --solutions--
79+
80+
```js
81+
function bouncer(arr) {
82+
return arr.filter(e => e);
83+
}
84+
```
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "Implement a Falsy Remover",
3+
"isUpcomingChange": false,
4+
"dashedName": "lab-falsy-remover",
5+
"helpCategory": "JavaScript",
6+
"challengeOrder": [
7+
{ "id": "adf08ec01beb4f99fc7a68f2", "title": "Implement a Falsy Remover" }
8+
],
9+
"usesMultifileEditor": true,
10+
"blockType": "lab",
11+
"blockLayout": "link"
12+
}

curriculum/structure/superblocks/full-stack-developer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,7 @@
377377
"lab-pyramid-generator",
378378
"lab-gradebook-app",
379379
"lecture-the-var-keyword-and-hoisting",
380+
"lab-falsy-remover",
380381
"lab-inventory-management-program",
381382
"lecture-understanding-modules-imports-and-exports",
382383
"lab-password-generator",

0 commit comments

Comments
 (0)