Skip to content

Commit 5fcf1f9

Browse files
committed
Falsy Bouncer
1 parent ea75439 commit 5fcf1f9

File tree

4 files changed

+47
-1
lines changed

4 files changed

+47
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ Once inside, run the command below:
1818
9. Anagram
1919
10. Pig-latin
2020
11. Chunk Array
21-
12. Combining Arrays Without Duplicates
21+
12. Combining Arrays Without Duplicates
22+
13. Falsy Bouncer

src/falsyBouncer/index.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// pick a solution and insert here to run the test.
2+
3+
4+
function falsyBouncer(array) {
5+
return array.filter((value) =>{
6+
return Boolean(value)
7+
})
8+
}
9+
10+
module.exports = falsyBouncer;

src/falsyBouncer/solutions.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// USING A FOR OF LOOP
2+
3+
function falsyBouncer(array) {
4+
let result =[]
5+
6+
for (value of array){
7+
if(value){
8+
result.push(value)
9+
}
10+
}
11+
12+
return result
13+
}
14+
15+
// USING .FILTER()
16+
17+
function falsyBouncer(array) {
18+
return array.filter((value) =>{
19+
return Boolean(value)
20+
})
21+
}
22+

src/falsyBouncer/test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const falsyBouncer = require('./index');
2+
3+
test('falsyBouncer is a function', () => {
4+
expect(typeof falsyBouncer).toEqual('function');
5+
});
6+
7+
test('Removes all falsy values', () => {
8+
expect(falsyBouncer([1, 0, null, '', 5])).toEqual([1, 5]);
9+
})
10+
11+
test('Removes all falsy values', () => {
12+
expect(falsyBouncer([NaN, 0, null, '', undefined])).toEqual([]);
13+
})

0 commit comments

Comments
 (0)