1.3 KiB
1.3 KiB
id, title, challengeType, forumTopicId, dashedName
id | title | challengeType | forumTopicId | dashedName |
---|---|---|---|---|
adf08ec01beb4f99fc7a68f2 | 偽値用心棒 | 5 | 16014 | falsy-bouncer |
--description--
すべての偽値を配列から取り除いてください。
JavaScriptにおける偽値とは、false
、null
、0
、""
、undefined
、そして NaN
です。
ヒント: それぞれの値をブール値に変換してみてください。
--hints--
bouncer([7, "ate", "", false, 9])
は [7, "ate", 9]
を返す必要があります。
assert.deepEqual(bouncer([7, 'ate', '', false, 9]), [7, 'ate', 9]);
bouncer(["a", "b", "c"])
は ["a", "b", "c"]
を返す必要があります。
assert.deepEqual(bouncer(['a', 'b', 'c']), ['a', 'b', 'c']);
bouncer([false, null, 0, NaN, undefined, ""])
は []
を返す必要があります。
assert.deepEqual(bouncer([false, null, 0, NaN, undefined, '']), []);
bouncer([null, NaN, 1, 2, undefined])
は [1, 2]
を返す必要があります。
assert.deepEqual(bouncer([null, NaN, 1, 2, undefined]), [1, 2]);
--seed--
--seed-contents--
function bouncer(arr) {
return arr;
}
bouncer([7, "ate", "", false, 9]);
--solutions--
function bouncer(arr) {
return arr.filter(e => e);
}
bouncer([7, "ate", "", false, 9]);