every and Empty Arrays
every and Empty Arrays
every returns true when no item fails the predicate. For an empty array, there is no failing item, so the method returns true.
That behavior is logical for the method but risky for business rules that require at least one approval. A correct validation helper may need two checks: one for the collection not being empty, and another for every item passing the predicate.
Your task: Complete allRequiredApprovalsPassed so it returns true only when there is at least one approval and every approval has required: true and status: "approved". Return a boolean for all inputs.
Free with a JS Exercises account
Sign in to start coding, run your solution, and keep your progress saved for later. No payment needed.
By continuing, you agree to our Terms and Privacy Policy. We'll send occasional product updates and news. You can unsubscribe anytime.
every and Empty Arrays
every returns true when no item fails the predicate. For an empty array, there is no failing item, so the method returns true.
That behavior is logical for the method but risky for business rules that require at least one approval. A correct validation helper may need two checks: one for the collection not being empty, and another for every item passing the predicate.
Your task: Complete allRequiredApprovalsPassed so it returns true only when there is at least one approval and every approval has required: true and status: "approved". Return a boolean for all inputs.