FrontendArk

Master Frontend Interviews

  • Practice
  • Playground
  • Resource
Easy

Compact

10mins

Implement a function compact(array) that returns a new array with all falsey values removed. Falsey values in JavaScript are: false, null, 0, "", undefined, and NaN.

Example

compact([0, 1, false, 2, '', 3, null, undefined, NaN]); // [1, 2, 3] compact(['a', '', 'b', null, 'c']); // ['a', 'b', 'c']

Code Editor

JavaScript Function

00:00
Loading...

Test Cases

No test results yet

Click "Run" to execute tests