Higher Order Functions

Implement filter

Implement filter

A filter helper asks the callback whether each item should stay. The returned array contains original items whose callback result was truthy.

That means the helper should not push the callback result itself. It should use the callback result as a decision, then preserve the item when the answer passes.

Your task: Complete customFilter so it returns a new array containing the items whose predicate passes. Pass item, index, and original array to the predicate. Do not use the built-in .filter() method inside your implementation.

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.

Implement filter

A filter helper asks the callback whether each item should stay. The returned array contains original items whose callback result was truthy.

That means the helper should not push the callback result itself. It should use the callback result as a decision, then preserve the item when the answer passes.

Your task: Complete customFilter so it returns a new array containing the items whose predicate passes. Pass item, index, and original array to the predicate. Do not use the built-in .filter() method inside your implementation.

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.