2.0 KiB
2.0 KiB
id, title, isRequired, challengeType, forumTopicId, localeTitle
| id | title | isRequired | challengeType | forumTopicId | localeTitle |
|---|---|---|---|---|---|
| adf08ec01beb4f99fc7a68f2 | Falsy Bouncer | true | 5 | 16014 | Фальшивый вышибала |
Description
false , null , 0 , "" , undefined и NaN . Подсказка: попробуйте преобразовать каждое значение в логическое. Не забудьте использовать Read-Search-Ask, если вы застряли. Напишите свой собственный код.
Instructions
Tests
tests:
- text: <code>bouncer([7, "ate", "", false, 9])</code> should return <code>[7, "ate", 9]</code>.
testString: assert.deepEqual(bouncer([7, "ate", "", false, 9]), [7, "ate", 9]);
- text: <code>bouncer(["a", "b", "c"])</code> should return <code>["a", "b", "c"]</code>.
testString: assert.deepEqual(bouncer(["a", "b", "c"]), ["a", "b", "c"]);
- text: <code>bouncer([false, null, 0, NaN, undefined, ""])</code> should return <code>[]</code>.
testString: assert.deepEqual(bouncer([false, null, 0, NaN, undefined, ""]), []);
- text: <code>bouncer([1, null, NaN, 2, undefined])</code> should return <code>[1, 2]</code>.
testString: assert.deepEqual(bouncer([1, null, NaN, 2, undefined]), [1, 2]);
Challenge Seed
function bouncer(arr) {
// Don't show a false ID to this bouncer.
return arr;
}
bouncer([7, "ate", "", false, 9]);
Solution
function bouncer(arr) {
return arr.filter(e => e);
}
bouncer([7, "ate", "", false, 9]);