Skip to content

Latest commit

 

History

History
25 lines (20 loc) · 969 Bytes

compact.md

File metadata and controls

25 lines (20 loc) · 969 Bytes
title tags author_title author_url author_image_url description image
compact
array,beginner
Deepak Vishwakarma
Implementation of "compact" in typescript, javascript and deno.

TS JS Deno

Removes falsy values from an array.

Use Array.prototype.filter() to filter out falsy values (false, null, 0, "", undefined, and NaN).

const compact = (arr: any[]) => arr.filter(Boolean);
compact([0, 1, false, 2, "", 3, "a", Number("e") * 23, NaN, "s", 34]); // [ 1, 2, 3, 'a', 's', 34 ]