2021-02-06 04:42:36 +00:00
|
|
|
---
|
|
|
|
id: adf08ec01beb4f99fc7a68f2
|
2021-03-04 09:49:46 -08:00
|
|
|
title: Rebote falsy
|
2021-02-06 04:42:36 +00:00
|
|
|
challengeType: 5
|
|
|
|
forumTopicId: 16014
|
|
|
|
dashedName: falsy-bouncer
|
|
|
|
---
|
|
|
|
|
|
|
|
# --description--
|
|
|
|
|
2021-03-04 09:49:46 -08:00
|
|
|
Quita todos los valores falsos de un arreglo.
|
2021-02-06 04:42:36 +00:00
|
|
|
|
2021-03-04 09:49:46 -08:00
|
|
|
Los valores falsos en JavaScript son `false`, `null`, `0`, `""`, `undefined` y `NaN`.
|
2021-02-06 04:42:36 +00:00
|
|
|
|
2021-03-04 09:49:46 -08:00
|
|
|
Sugerencia: Intenta convertir cada valor a booleano.
|
2021-02-06 04:42:36 +00:00
|
|
|
|
|
|
|
# --hints--
|
|
|
|
|
2021-03-04 09:49:46 -08:00
|
|
|
`bouncer([7, "ate", "", false, 9])` debe devolver `[7, "ate", 9]`.
|
2021-02-06 04:42:36 +00:00
|
|
|
|
|
|
|
```js
|
|
|
|
assert.deepEqual(bouncer([7, 'ate', '', false, 9]), [7, 'ate', 9]);
|
|
|
|
```
|
|
|
|
|
2021-03-04 09:49:46 -08:00
|
|
|
`bouncer(["a", "b", "c"])` debe devolver `["a", "b", "c"]`.
|
2021-02-06 04:42:36 +00:00
|
|
|
|
|
|
|
```js
|
|
|
|
assert.deepEqual(bouncer(['a', 'b', 'c']), ['a', 'b', 'c']);
|
|
|
|
```
|
|
|
|
|
2021-03-04 09:49:46 -08:00
|
|
|
`bouncer([false, null, 0, NaN, undefined, ""])` debe devolver `[]`.
|
2021-02-06 04:42:36 +00:00
|
|
|
|
|
|
|
```js
|
|
|
|
assert.deepEqual(bouncer([false, null, 0, NaN, undefined, '']), []);
|
|
|
|
```
|
|
|
|
|
2021-03-04 09:49:46 -08:00
|
|
|
`bouncer([null, NaN, 1, 2, undefined])` debe devolver `[1, 2]`.
|
2021-02-06 04:42:36 +00:00
|
|
|
|
|
|
|
```js
|
|
|
|
assert.deepEqual(bouncer([null, NaN, 1, 2, undefined]), [1, 2]);
|
|
|
|
```
|
|
|
|
|
|
|
|
# --seed--
|
|
|
|
|
|
|
|
## --seed-contents--
|
|
|
|
|
|
|
|
```js
|
|
|
|
function bouncer(arr) {
|
|
|
|
return arr;
|
|
|
|
}
|
|
|
|
|
|
|
|
bouncer([7, "ate", "", false, 9]);
|
|
|
|
```
|
|
|
|
|
|
|
|
# --solutions--
|
|
|
|
|
|
|
|
```js
|
|
|
|
function bouncer(arr) {
|
|
|
|
return arr.filter(e => e);
|
|
|
|
}
|
|
|
|
|
|
|
|
bouncer([7, "ate", "", false, 9]);
|
|
|
|
```
|