Higher Order Functions

Find and Missing Results

Find and Missing Results

When find does not locate a match, it returns undefined. Production code often converts that into an explicit fallback when callers need a stable contract.

The key decision is whether the caller wants one record or a collection. Returning an array here would force every caller to unpack a list when the business rule only allows one first match.

Your task: Complete firstOverdueInvoice so it returns the first unpaid invoice whose daysLate is greater than 0. Return null when there is no overdue invoice.

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.

Find and Missing Results

When find does not locate a match, it returns undefined. Production code often converts that into an explicit fallback when callers need a stable contract.

The key decision is whether the caller wants one record or a collection. Returning an array here would force every caller to unpack a list when the business rule only allows one first match.

Your task: Complete firstOverdueInvoice so it returns the first unpaid invoice whose daysLate is greater than 0. Return null when there is no overdue invoice.

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.

Console

Run code to see output.