Skip to content

Instantly share code, notes, and snippets.

@ratbeard
Created March 27, 2019 16:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ratbeard/700c4014aa3b95a49bd9458a55e59526 to your computer and use it in GitHub Desktop.
Save ratbeard/700c4014aa3b95a49bd9458a55e59526 to your computer and use it in GitHub Desktop.
type Falsey = undefined | null | 0 | false | '';
/** Returns a new array with falsey values removed */
export function compact<T>(array: (T | Falsey)[]): T[] {
// .ts is not smart enough about filter()
return array.filter(item => !!item) as T[];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment