Higher Order Functions

Find Predicate Bugs

Find Predicate Bugs

A find callback should test each item and return a boolean-like answer. If the predicate accidentally assigns to a property, the search can appear to work while corrupting the records it inspected.

That mistake is especially risky in lookup helpers because they are called from many places. A correct lookup returns the matching record, leaves every record unchanged, and gives a clear fallback when nothing matches.

Your task: Fix getUserById so it returns the user with the requested id. Return null when no user matches, and do not mutate any user object.

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 Predicate Bugs

A find callback should test each item and return a boolean-like answer. If the predicate accidentally assigns to a property, the search can appear to work while corrupting the records it inspected.

That mistake is especially risky in lookup helpers because they are called from many places. A correct lookup returns the matching record, leaves every record unchanged, and gives a clear fallback when nothing matches.

Your task: Fix getUserById so it returns the user with the requested id. Return null when no user matches, and do not mutate any user object.

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.