Created
March 27, 2019 16:53
-
-
Save ratbeard/700c4014aa3b95a49bd9458a55e59526 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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