Skip to content

New function isEmpty #6

@Alexnortung

Description

@Alexnortung

Let's say I want to get the first item in an array, but i want to make sure that the array is empty first. you can do it in these two ways

if (isNonEmpty(arr)) {
  const first = arr[0];
}

or

if (!isNonEmpty(arr)) {
  return;
}
const first = arr[0];

I would normally prefer the second option as it would allow for less nesting.

The problem is that !isNonEmpty(arr) doesn't really look good and is kinda weird to read (not is not empty). Here it would be much easier to just use isEmpty(arr). This would also read nicely if you want to use !isEmpty(arr) and still feels intuitive.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions