every() checks if every of element in array is satisfied with a given condition. When meeting statement, this function returns true and vice versa.
So, only when all of elements pass the test, it returns true.
some() checks if any of element in array is satisfied with a given condition. When meeting statement, this function returns true and vice versa.
const valid =
state.companyUsersList.filter(user => Object.values(user).includes(''))
.length === 0 &&
state.companyUsersList.filter(user => user.isDefault).length === 1
const valid =
state.companyUsersList.every(user => !Object.values(user).includes('')) &&
state.companyUsersList.some(user => user.isDefault)
By using every and some, no need to add length property to get Boolean type. It can be simpler and cleaner code!