Files
Nicholas Carrigan (he/him) 3da4be21bb chore: seed chinese traditional (#42005)
Seeds the chinese traditional files manually so we can deploy to
staging.
2021-05-05 22:43:49 +05:30

1.1 KiB
Raw Permalink Blame History

id, title, challengeType, forumTopicId, dashedName
id title challengeType forumTopicId dashedName
adf08ec01beb4f99fc7a68f2 過濾數組中的假值 5 16014 falsy-bouncer

--description--

從數組中移除所有假值falsy values

JavaScript 中的假值有 falsenull0""undefinedNaN

提示可以考慮將每個值都轉換爲布爾值boolean

--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]);