DEV Community

Discussion on: 1 line of code: How to check if an Array is empty

Collapse
 
martinkr profile image
Martin Krause

Thank you all for your contributions.

I closely followed the discussions and took some valuable insights for this and the upcoming code snippets.

For all the functions in this series we will stick to certain assumptions:

  • as long as it's javascript, we assume the user provides valid input. No type checking or other verifications.
    E.g.: No more checking if it's actually an array

  • keep the functions as simple as possible and reduce the functionality to a core. E.g.: empty items are still items, if necessary clean the array before passing it to the function.

I adjusted the code to the function LUKESHIRU suggested.

It seems to be the simplest form and passes all my test cases (given the assumptions).

Thanks you again and looking forward to your contributions to the upcoming articles.

Cheers!

Some comments have been hidden by the post's author - find out more