I am struggling with validating an array of objects being sent to the server. It seems that my current code is not working properly when the array is empty or if the objects within it are invalid. I'm confused about why it's not functioning as expected.
Here is the code snippet I am using:
const ingredientValidator = ingredients.some(({ingredient, quantity})=>{
ingredient.trim().length == 0 || quantity.trim().length == 0
})
if(ingredientValidator){
return res.status(409).send({
message: 'fully point ingredients'
})
}
What could be causing this issue?
P.S An example of an array of objects:
[
{
ingredient:'foo',
quantity:'bar'
},
{
ingredient:'foo',
quantity:'bar'
},
{
ingredient:'foo',
quantity:'bar'
}
]
Can you provide guidance on how to solve this problem?