FrontendAtlas
Study
▾
Dashboard
Pricing
Get full access
</> Code
Test cases
Language
JavaScript
TypeScript
export default function compact(arr) { // TODO: Remove all falsy values from the array throw new Error('Not implemented'); }
import compact from './compact'; describe('compact', () => { test('removes falsy values', () => { expect(compact([0, 1, false, 2, '', 3])).toEqual([1, 2, 3]); }); test('returns same array when all truthy', () => { expect(compact(['a', true, 42])).toEqual(['a', true, 42]); }); test('removes null and undefined', () => { expect(compact([null, undefined, 'x'])).toEqual(['x']); }); test('removes NaN', () => { expect(compact([NaN, 1, 2])).toEqual([1, 2]); }); test('handles empty array', () => { expect(compact([])).toEqual([]); }); });
▶ Run tests
Results
Console
Run tests to see results.