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

Bug in isStringArray #7

Open
artola opened this issue Jan 13, 2023 · 0 comments
Open

Bug in isStringArray #7

artola opened this issue Jan 13, 2023 · 0 comments

Comments

@artola
Copy link

artola commented Jan 13, 2023

I was reading the code to evaluate the usage, I found this line:

return false

The problem is that the return false does nothing more than finish the iteration and moving to the next element of the array.

    if (Array.isArray(arr)) {

        arr.forEach(item => {
           if(typeof item !== 'string'){
              return false  // <======= here
           }
        })

        return true
    }

Probably it was intended this optimised version that will stop asap:

    if (Array.isArray(arr)) {

        return arr.every(item => typeof item === 'string')

    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant