Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Array remove nullish #73

Merged
merged 10 commits into from
Oct 17, 2023
Merged

Array remove nullish #73

merged 10 commits into from
Oct 17, 2023

Conversation

CarlosGamero
Copy link
Contributor

@CarlosGamero CarlosGamero commented Oct 17, 2023

Changes

Adding removeNullish and removeFalsy to facilitate array cleaning

Checklist

  • Apply one of following labels; major, minor, patch or skip-release
  • I've updated the documentation, or no changes were necessary
  • I've updated the tests, or no changes were necessary

@CarlosGamero CarlosGamero self-assigned this Oct 17, 2023
src/utils/arrayUtils.ts Outdated Show resolved Hide resolved
Comment on lines 29 to 41
/**
* Return a copy of the given array without null or undefined values
*/
export function removeNullish<T>(array: readonly (T | null | undefined)[]): T[] {
return array.filter((e) => e !== undefined && e !== null) as T[]
}

/**
* Return a copy of the given array without falsy values (eg: false, 0, '', null, undefined)
*/
export function removeFalsy<T>(array: readonly (T | null | undefined)[]): T[] {
return array.filter((e) => e) as T[]
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Finally, I added both because I can think of use cases where both can be useful, but feel free to disagree

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's a great call!

docs/array-utils.md Outdated Show resolved Hide resolved
Co-authored-by: Igor Savin <iselwin@gmail.com>
src/utils/arrayUtils.ts Outdated Show resolved Hide resolved
CarlosGamero and others added 2 commits October 17, 2023 19:42
Co-authored-by: Igor Savin <iselwin@gmail.com>
Copy link
Collaborator

@kibertoad kibertoad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great job!

@CarlosGamero CarlosGamero merged commit da72a58 into main Oct 17, 2023
4 checks passed
@CarlosGamero CarlosGamero deleted the array_removeNullish branch October 17, 2023 17:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants